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

后端 未结 1 633
星月不相逢
星月不相逢 2021-01-18 02:12

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.

I\'m attem

相关标签:
1条回答
  • 2021-01-18 02:43

    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
    
    0 讨论(0)
提交回复
热议问题