How to execute a stored procedure from Access using linked tables

I have an Access 2003 database that connects to a SQL Server 2008 mailbox through ODBC. Tables from SQL Server are connected as linked tables in Access. I have a stored procedure on SQL Server that I am trying to execute using ADO code. The problem is that Access cannot find the procedure. What do I need to do in Access to execute this stored procedure? Some facts ...

The stored procedure in question takes one parameter, which is an integer. The stored procedure returns a record set, which I hope to use as a data source for the ListBox.

Here is my ADO code in Access ...

Private Sub LoadUserCaseList(userID As Integer)

  Dim cmd As ADODB.Command

  Set cmd = New ADODB.Command
  cmd.ActiveConnection = CurrentProject.Connection
  cmd.CommandType = adCmdStoredProc
  cmd.CommandText = "uspGetUserCaseSummaryList"

  Dim par As New ADODB.Parameter
  Set par = cmd.CreateParameter("userID", adInteger)
  cmd.Parameters.Append par
  cmd.Parameters("userID") = userID

  Dim rs As ADODB.Recordset
  Set rs = cmd.Execute()
  lstUserCases.Recordset = rs

End Sub

, , , " Microsoft Jet Jet " uspGetUserCaseSummaryList ".

+3
1

CurrentProject.Connection - Access. , Immediate:

Debug.Print CurrentProject.Connection

ADODB.Connection , SQL Server. ADODB.Command .

. ADODB.Command Execute . , 3 .

Private Sub GetCenterCodes()
    Dim cnn As ADODB.Connection
    Dim rs As ADODB.Recordset

    Set cnn = New ADODB.Connection
    cnn.ConnectionString = "Provider=SQLOLEDB;Data Source=VM2003\sqlexpress;" _
        & "User ID=foo;Password=bar;Initial Catalog=Inventory"
    cnn.Open
    Set rs = New ADODB.Recordset
    Set rs = cnn.Execute("EXEC uspGetCenterCodes 14, 14, 501")
    Debug.Print rs(0), rs(1), rs(2)
    rs.Close
    Set rs = Nothing
    cnn.Close
    Set cnn = Nothing
End Sub

ConnectionStrings.com

+6

Source: https://habr.com/ru/post/1750196/


All Articles