从Excel(VBA)运行存储过程的SQL Server 2005

我想在我的SQL服务器上运行一个存储过程。 我认为连接types是'ODBC',但我不确定,我正在尝试下面的:

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

当我尝试运行这个我收到错误:运行时错误'3709';

请求的操作需要一个OLE DB会话对象,目前的提供者不支持。

我相信我只是让我的连接types错误的地方,但有人能帮我吗?

为了确认,我试图通过ODBC连接到SQLServer2005,通过Excel VBA(2003)

非常感谢。

使用FIX进行更新:在使用“.ActiveConnection =”“”之前,您必须打开连接。 我编辑了原始代码来显示这个改变。

使用FIX进行更新:在使用“.ActiveConnection =”“”之前,您必须打开连接。 我编辑了原始代码来显示这个改变。