I am trying to run a stored procedure on my SQL server. I think the connection type is 'ODBC', but I am unsure, I am trying the below:
'Declare some variables
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim strSQL As String
Dim gway As String
'Create a new Connection object
Set cnn = New A开发者_如何学PythonDODB.Connection
'Set the connection string
cnn.ConnectionString = connectionString 'See http://connectionstrings.com if you need help on building this string for your database!
'Create a new Command object
Set cmd = New ADODB.Command
'Associate the command with the connection
'Open the Connection to the database
cnn.Open
cmd.ActiveConnection = cnn
VARIABLE= "param"
strSQL = "EXECUTE dbo.NAMEWASHERE '" & VARIABLE & "';"
cmd.Execute strSQL
'Close the connection again
cnn.Close
When I try to run this I recieve the error: Run-time error '3709';
Requested operation requires an OLE DB Session object, which is not supported by the current provider.
I am sure I am just getting my connection type wrong somewhere, but could anybody help me out?
To confirm, I'm trying to connect via ODBC to an SQLServer2005, via Excel VBA (2003)
Many thanks.
UPDATE WITH FIX: You must open the connection before using ".ActiveConnection = """. I have editted the original code to show this change.
UPDATE WITH FIX: You must open the connection before using ".ActiveConnection = """. I have editted the original code to show this change.
精彩评论