ADODB仅适用于本地计算机

时间:2018-04-08 14:25:15

标签: sql-server vba excel-vba adodb excel

感谢大卫的帮助。我根据您建议的链接进行了更改。我错过了什么,因为我仍然收到相同的消息

  [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied.

I enabled "Yes" on IP5

I also added a new inbound rule

我正在使用VBA将数据输入SQL服务器。代码工作正常。 我使用的是SQL Server 2014.数据库位于我的服务器上。这些计算机是否具有安全,经过身份验证的远程访问我的机器/服务器?用户通过Excel .xlsm文件输入信息。

这就是问题所在。我将我的Excel / VBA .xlsm文件发送给登录到不同计算机的其他人。

当他们尝试在不同的计算机上输入信息时,代码不起作用。

代码仅在我使用包含数据库的计算机时才有效。

如何修改连接字符串以使其在其他计算机上运行?我尝试了很多不同的连接,但没有任何作用。

Private Sub Click()


Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

Dim strconn As String

strconn = "Driver={SQL Server}; Server=DESKTOP-MyServer; Database = Test; User ID = myid; Password = mypassword;"

cn.Open strconn
cn.Close
Set cn = Nothing
MsgBox "Connection Works!"


End Sub

我收到的VBA错误消息如下:

[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist
or access denied.

1 个答案:

答案 0 :(得分:1)

要从网络客户端访问SQL Server,您必须

1)Configure SQL Server to Listen on TCP/IP。最简单的配置是让SQL侦听默认端口(1433)。

2)Configure the Windows Firewall to allow inbound connections to SQL Server