【问题标题】:VBA connection to SQL Server denied from other computer其他计算机拒绝 VBA 与 SQL Server 的连接
【发布时间】:2017-02-07 22:36:58
【问题描述】:

我有一个 VBA 宏,它连接到数据库以提取一些数据并且工作正常。但是,当另一个部门的另一个人尝试从他的计算机上运行该文件时,他会收到一个错误:

我的 VBA 连接字符串如下:

Sub exportLens()
Dim cnn As New ADODB.Connection
Dim rst As New ADODB.Recordset
Dim ConnectionString As String
Dim StrQuery As String
Sheets("data").Range("A2:C100000").Clear

ConnectionString = "Provider=SQLOLEDB.1;Password=xxxxx;Persist Security Info=True;User ID=SQLxxx;Data Source=xx.xx5.xx.90,xx33;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Use Encryption for Data=False;Tag with column collation when possible=False;Initial Catalog=NasrWeb"

任何想法,为什么这不能在我朋友的电脑上运行?

感谢您的帮助。

【问题讨论】:

  • 他能ping通你要连接的服务器吗?
  • 尽可能使用 Windows 身份验证。不要在 VBA 代码的连接字符串中存储密码和用户 ID。 VBA 代码,即使是受保护的,也不安全。
  • DataSource 应该是 xxx.xxx.xxx.xxx:xxx(分号)而不是 xxx.xxx.xxx.xxx,xxxx(逗号)
  • 没有。逗号是正确的stackoverflow.com/questions/5294721/…

标签: sql-server vba excel


【解决方案1】:

可能是以下情况之一:

  1. 没有为 SQL Server 实例启用远程连接。

  2. 端口未添加到防火墙例外列表中

  3. SQL Server 实例的 IP 地址被防火墙阻止

【讨论】:

  • 这两种情况都不会导致 OP 也遇到同样的连接问题吗?
猜你喜欢
  • 1970-01-01
  • 2018-08-06
  • 2020-09-28
  • 1970-01-01
  • 2020-10-03
  • 2019-10-18
  • 1970-01-01
  • 2023-03-30
  • 2013-09-20
相关资源
最近更新 更多