gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 20:19:55 25 4
gpt4 key购买 nike

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com