【发布时间】:2012-03-20 22:28:09
【问题描述】:
我有以下 VBA 代码,并且收到此问题标题中所述的错误消息。有人可以帮忙吗?我通常不写这种代码:
Sub Save_To_DB()
'Declare some variables
Dim cnn As ADODB.Connection
Dim cmd As ADODB.Command
Dim strSQL As String
'Create a new Connection object
Set cnn = New ADODB.Connection
'Set the connection string
cnn.ConnectionString = "Server=server_name;Database=database_name;Trusted_Connection=True;"
'Open the Connection to the database
cnn.Open **<-THE ERROR THROWS HERE**
'Create a new Command object
Set cmd = New ADODB.Command
'Associate the command with the connection
cmd.ActiveConnection = cnn
'Go on to write the SQL statement and execute
编辑:好的,我解决了,需要在连接字符串中包含Driver={SQL Native Client};。
【问题讨论】:
标签: sql sql-server-2008 excel vba