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

那年仲夏 提交于 2019-12-01 16:28:32

You have not opened your connection yet. I think you need a Con.Open before you assign it to the Command object.

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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!