简体   繁体   English

请求的操作需要OLE DB会话对象... - 通过ADO将Excel连接到SQL服务器

[英]Requested operation requires an OLE DB Session object… - Connecting Excel to SQL server via ADO

I'm attempting to take Excel 2003 and connect it to SQL Server 2000 to run a few dynamicly generated SQL Queries which ultimately filling certain cells. 我正在尝试使用Excel 2003并将其连接到SQL Server 2000以运行一些动态生成的SQL查询,这些查询最终会填充某些单元格。

I'm attempting to do this via VBA via ADO (I've tried 2.8 to 2.0) but I'm getting an error while setting the ActiveConnection variable which is inside the ADODB.Connection object. 我试图通过ADO通过VBA执行此操作(我已经尝试过2.8到2.0)但是在设置ADODB.Connection对象内部的ActiveConnection变量时出现错误。 I need to resolve this pretty quick... 我需要快速解决这个问题......

Requested operation requires an OLE DB Session object, which is not supported by the current provider. 请求的操作需要OLE DB会话对象,当前提供程序不支持该对象。

I'm honestly not sure what this error means and right now I don't care. 老实说,我不确定这个错误意味着什么,现在我不在乎。 How can get this connection to succeed so that I can run my queries? 如何才能使此连接成功,以便我可以运行查询?

Here is my VB code: 这是我的VB代码:

Dim SQL As String, RetValue As String
SQL = " select top 1 DateTimeValue from SrcTable where x='value' " 'Not the real SQL
RetValue = ""


Dim RS As ADODB.Recordset
Dim Con As New ADODB.Connection
Dim Cmd As New ADODB.Command

Con.ConnectionString = "Provider=sqloledb;DRIVER=SQL Server;Data Source=Server\Instance;Initial Catalog=MyDB_DC;User Id=<UserName>;Password=<Password>;"
Con.CommandTimeout = (60 * 30)


Set Cmd.ActiveConnection = Con   ''Error occurs here.

' I'm not sure if the rest is right. I've just coded it. Can't get past the line above.
Cmd.CommandText = SQL
Cmd.CommandType = adCmdText

Con.Open
Set RS = Cmd.Execute()

If Not RS.EOF Then

    RetValue = RS(0).Value
    Debug.Print "RetValue is: " & RetValue

End If
Con.Close

I imagine something is wrong with the connection string but I've tried over a dozen variations. 我想连接字符串有问题,但我尝试了十几种变体。 Now I'm just shooting in the dark.... 现在我只是在黑暗中拍摄....

Note/Update : To make matters more confusing, if I Google for the error quote above, I get a lot of hits back but nothing seems relevant or I'm not sure what information is relevant.... 注意/更新 :为了让事情更加混乱,如果我谷歌上面的错误报价,我得到了很多回击,但似乎没有任何相关性,或者我不确定哪些信息是相关的....

I've got the VBA code in "Sheet1" under "Microsoft Excel Objects." 我在“Microsoft Excel Objects”下的“Sheet1”中获得了VBA代码。 I've done this before but usually put things in a module. 我以前做过这个,但通常把东西放在一个模块中。 Could this make a difference? 这会有所作为吗?

You have not opened your connection yet. 您尚未打开连接。 I think you need a Con.Open before you assign it to the Command object. 我认为在将其分配给Command对象之前需要一个Con.Open

Con.ConnectionString = "Provider=sqloledb;DRIVER=SQL Server;Data Source=Server\Instance;Initial Catalog=MyDB_DC;User Id=<UserName>;Password=<Password>;"
Con.CommandTimeout = (60 * 30)

Con.Open

Set Cmd.ActiveConnection = Con   'Error occurs here.

Cmd.CommandText = SQL
Cmd.CommandType = adCmdText

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 请求的操作需要一个OLE DB会话对象— VB6至SQL Server 2000 - Requested operation requires an OLE DB Session object — VB6 to SQL Server 2000 使用ADO命令在SQL Server中运行存储过程时如何解决“多站OLE DB操作…”错误 - How to fix “Multiple-stop OLE DB operation…” errors when using ADO Command to run stored procedure in SQL Server 请求的操作需要在SQL Server中进行提升(以管理员身份运行) - The requested operation requires elevation (Run as administrator) in SQL Server 无法执行请求的操作,因为链接服务器“SSAS”的 OLE DB 提供程序“MSOLAP”不支持所需的接口 - The requested operation could not be performed because OLE DB provider 'MSOLAP' for Linked server 'SSAS' does not support the required interface 使用Excel VBA中的ADO通过网络连接到SQL Server - Connecting to SQL Server over network using ADO from Excel VBA 表锁定-超时-通过Excel VBA到SQL Server的ADO连接 - Table Lock - Timeout - ADO connection to SQL server via Excel VBA ADO 与 OLE DB 有什么关系? - How is ADO related to OLE DB? SQL Server目标与OLE DB目标 - SQL Server Destination vs OLE DB Destination SQL Server BIDS OLE DB输入 - SQL Server BIDS OLE DB inputs 使用ADO.NET同时连接到SQL Server,Oracle,DB2和MySQL? - Connecting to SQL Server, Oracle, DB2 and MySQL simultaneously using ADO.NET?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM