我有以下 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};
。
最佳答案
这意味着您的连接字符串错误,请在此处查找正确的 http://www.connectionstrings.com/ .
如果您在找到适合您的内容时遇到困难,请使用外部数据向导附加一个表,然后查看它提供的连接字符串:
CurrentDB.TableDefs("MyLinkedTable").Connect
关于sql - VBA 连接到 SQL Server 数据源名称未找到且未指定默认驱动程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9532957/