未找到 VBA 连接到 SQL Server 数据源名称且未指定默认驱动程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9532957/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA connect to SQL Server data source name not found and no default driver specified?
提问by mezamorphic
I have the following VBA code and I am getting the error message stated in the title of this question. Can anybody please help? I don't usually write this sort of code:
我有以下 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
EDIT: Ok I solved it, needed to include Driver={SQL Native Client};
in the connection string.
编辑:好的,我解决了,需要包含Driver={SQL Native Client};
在连接字符串中。
采纳答案by Fionnuala
This means that your connection string is wrong, look here for the right one http://www.connectionstrings.com/.
这意味着您的连接字符串是错误的,请在此处查找正确的http://www.connectionstrings.com/。
If you are having difficulties finding what will work for you, attach a table using the external data wizard and then look at the connection string that it provides:
如果您很难找到适合您的方法,请使用外部数据向导附加一个表,然后查看它提供的连接字符串:
CurrentDB.TableDefs("MyLinkedTable").Connect