我正在尝试使用以下函数打开连接:
Public cn1 As New ADODB.Connection
'Sub to open connection to database
Public Function OpenConnection(ByVal strOpenConnectionString As String, _
Optional ByVal lngOpenConnectionTimeout As Long = 3600) As Long
With cn1
.CursorLocation = ADODB.CursorLocationEnum.adUseClient
.Mode = ADODB.ConnectModeEnum.adModeUnknown
.ConnectionTimeout = lngOpenConnectionTimeout
.CommandTimeout = lngOpenConnectionTimeout
.ConnectionString = strOpenConnectionString
End With
Try
cn1.Open()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
OpenConnection = cn1.State
End Function
我正在为我的连接使用Windows身份验证,我的连接字符串是:
"Integrated Security=SSPI;Initial Catalog=Test;Data Source=PEDRAM-PC\PEDRAM"
当我使用sql连接时,我可以轻松连接,但我需要使用该ado db对象,因为它是我的公司代码。 我得到以下异常:
谁能告诉我我做错了什么?
答案 0 :(得分:2)
您需要为ADODB使用不同的连接字符串。试试这个
Provider=SQLOLEDB;Initial Catalog=Test;Data Source=PEDRAM-PC\PEDRAM;Trusted_connection=yes;