'Could not find stored procedure Excel VBA Error

Error occurs on this line of code

Set rs = conn.Execute("GetReportingHierarchy")

enter image description here

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 Stored Procedure



Solution 1:[1]

Finally found the solution.

It should be fully qualified reference.

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Sixthsense