[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

VB6: How to call SQLServer 2000 system procedure sp_fkeys

Posted on 2004-09-01
4
Medium Priority
?
224 Views
Last Modified: 2013-12-25
This is a frustrating one.  If I use "sp_fkeys 'tblControl'" in Query Analzyer, I get the information I'm after (relationships the table is participating in).  HOW do I call this stored procedure from VB6?? It's driving me nuts!

I've tried the code below (which I got off the web somewhere) and passed in "sp_fkeys" and "tblControl".  I don't get any errors, but the recordset has no records in it.  When I run it through Query Analyser, 3 records return (which is correct, since the table is participating in three relationships):

Public Function CallStoredProc(sProcName As String, sParameter As String) As Integer
    'TH 22/01/01 call a stored procedure from vb
    Dim cmd As New Command
    Dim prm As New ADODB.Parameter
    Dim rs As New ADODB.Recordset
    'create new stored proc object
    Set cmd = New ADODB.Command
    'add a paramter with value of "sParameter"
    Set prm = cmd.CreateParameter("param1", adBSTR, adParamInput, 1, sParameter)

    With cmd
        .Parameters.Append prm
        .ActiveConnection = gcn
        .CommandType = adCmdStoredProc
        .CommandText = sProcName
    End With
   
    Set rs = cmd.Execute
   
    If Not rs.State = adStateOpen Then
        rs.Open
    End If
    If gcn.Errors.Count > 0 Then
        MsgBox gcn.Errors.Item(0)
    End If
    'Set frmMain.list1.DataSource = rs
    MsgBox rs.RecordCount
End Function
0
Comment
Question by:MushyPeas
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 29

Accepted Solution

by:
leonstryker earned 1000 total points
ID: 11963339
Hmm, try this:

Public Function CallStoredProc(sProcName As String, sParameter As String) As Integer
Dim rs As ADODB.Recordset
    Set rs = New ADODB.Recordset
    rs.Open "Exec " & sProcName & "'" & sParameter & "'"
    MsgBox rs.RecordCount
    CallStoredProc = rs.RecordCount
End Function


Leon
0
 
LVL 1

Author Comment

by:MushyPeas
ID: 11969268
Thank you!!!  Can you explain this to me - why "Exec".  Is this not the same as saying cmd.execute (which I also tried)

Is this an acceptable/efficient/safe method to use?

Thanks

M
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
Suggested Courses

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question