vba - 使用 SSL 证书连接 SQL 服务器的 VBA 连接字符串
问题描述
我在我的 VB 脚本中使用 VBA 连接字符串连接 SQL 服务器。它之前运行顺利。
最近服务器团队安装了 SSL 证书,其中我的宏现在没有运行,并说明 SSL 安全错误,如下图所示。
谁能帮我解决这个问题。
提前致谢!!!
问候,
解决方案
我会在打开连接字符串之前连接它所需的值,而不是 on cnSrc.Open
。
我使用 VBA 并使用 ADO 每天查询 SQL 服务器,我对连接字符串使用以下格式:
Provider=SQLOLEDB.1;User ID=UserName;Password=Password;Data Source=SeverName;Initial Catalog=DataBaseName
您可以使用下面的代码进行测试:
Private Sub TestConnection()
Dim cnSrc As ADODB.Connection
Dim CONNECTION_STRING As String
Dim cnServer As String, cndb As String, cnUser As String, cnPwd As String
cnServer = "SeverName"
cndb = "DataBaseName"
cnUser = "UserName"
cnPwd = "Password"
CONNECTION_STRING = "Provider=SQLOLEDB.1;User ID=" & cnUser & ";Password=" & cnPwd & ";" & _
"Data Source=" & cnServer & ";Initial Catalog=" & cndb
On Error GoTo CleanFail
Set cnSrc = New ADODB.Connection
cnSrc.Open CONNECTION_STRING
'bit wise comparison to check the connection's state
Debug.Assert (cnSrc.State And adStateOpen) = adStateOpen 'Debug.Assert pauses execution if false
CleanExit:
'close the connection
If Not cnSrc Is Nothing Then: If (cnSrc.State And adStateOpen) = adStateOpen Then cnSrc.Close
Set cnSrc = Nothing
Exit Sub
CleanFail:
Resume CleanExit
End Sub
推荐阅读
- c++ - 如何在模板化转换运算符中消除这种构造的歧义?
- unity3d - 来自 amazon s3 的资产在部署到移动设备时不会加载
- header - FileHelpers 可以从同一个文件中提取不同的记录吗
- python-3.x - 文本自动完成不适用于个人包的 Jupyter 导入
- javascript - 如何计算 JSON 对象中的值?
- monitoring - 使用 Prometheus 警报管理器使用多个指标发送警报
- vba - 访问 VBA 记录集以在不同表单上查找第一个错误?
- performance - Go 按位运算性能之谜
- android - MotionLayout 和 ConstraintLayout 不围绕儿童高度设置动画
- c++ - 控制台未正确读取输入字符串