简体   繁体   中英

Could not find stored procedure Excel VBA Error

Error occurs on this line of code

Set rs = conn.Execute("GetReportingHierarchy")

在此处输入图像描述

Sub RunCode()
Dim sConnString As String,conn As adodb.Connection,rs As adodb.Recordset

sConnString = "PROVIDER=SQLOLEDB;" & _
          "Data Source=MyServerIPAndPort" & _
          "Initial Catalog=MyDB;" & _
          "User Id=MyUserName;" & _
          "Password=MyPassword;"

sConnString = sConnString
Set conn = New adodb.Connection
Set rs = New adodb.Recordset

conn.Open sConnString
Set rs = conn.Execute("GetReportingHierarchy")

If Not rs.EOF Then
    Range("A6").CopyFromRecordset rs
    rs.Close
Else
    MsgBox "Error: No records returned.", vbCritical
End If

If CBool(conn.State And adStateOpen) Then conn.Close
Set conn = Nothing
Set rs = Nothing
   
End Sub

SQL Server Stored Procedure

SQL Server 存储过程

Finally found the solution.

It should be fully qualified reference.

Set rs = conn.Execute("MyDBName.dbo.GetReportingHierarchy")

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM