我想在Excel中使用下面的代码在SQL Server上打开记录集,但得到3709 - The connection cannot be used to perform this operation. It is either closed or invalid in this context.
错误。我要去哪里错了?:错误3709当通过ADODB.connection连接到SQL Server 2008在Excel中
编辑:
它现在的工作,我会更新代码如下:
'Declare variables'
Set objMyConn = New ADODB.Connection
Set objMyRecordset = New ADODB.Recordset
Dim strSQL As String
'Open Connection'
objMyConn.ConnectionString = "Driver={SQL Server};Server=SERVER\SERVER; Database=we_ci_db; Trusted_Connection=Yes"
objMyConn.Open
'Set and Excecute SQL Command'
strSQL = "select * from tblUsers"
'Open Recordset'
Set objMyRecordset.ActiveConnection = objMyConn
objMyRecordset.Open strSQL
'Copy Data to Excel'
ActiveSheet.Range("A1").CopyFromRecordset (objMyRecordset)
本身是没有错的字符串,我已经尝试了几种组合,这是完全不同的,但所有工作。这是我的第一个“开放”路线,我没有对。我需要使用其他属性,cnn,adOpenStatic等... – aSystemOverload 2012-08-13 14:41:11