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
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.