sql - VBA 连接到 SQL Server 数据源名称未找到且未指定默认驱动程序?

标签 sql sql-server-2008 excel vba

我有以下 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/

相关文章:

excel - 关于 Dim 和 Set Worksheet 的一些疑问

excel - 使用 VBA 复制多个范围

mysql - SQL BETWEEN 区分大小写

php - 按 WP_Query 中的自定义字段(数字)排序

SQL查询源代码

sql - 在 SQL Server 中计算排除周末(周一至周五)的天数

mysql - Sybase 到 MySQL 自动导出

MySql:通过其父表的 id 从其他表获取表的总和,并返回具有与 parent_id 相关的总和值的所有子表

sql-server - SQL Server 2008 中的枚举类型?

regex - 使 Excel 公式将字符串视为正则表达式