VBA连接到SQL Server数据源名称未find并且没有指定默认驱动程序?

我有以下的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}; 在连接string中。

这意味着你的连接string是错误的,在这里找一个正确的http://www.connectionstrings.com/

如果您在查找哪些内容时遇到困难,请使用外部数据向导附加一个表,然后查看它提供的连接string:

 CurrentDB.TableDefs("MyLinkedTable").Connect