sql-server - 通过Excel ADODB在sql server中随机“登录超时”
问题描述
用户从 Excel 向 SQL Server 数据库发送数据。现在随机用户收到“登录超时过期”消息。与上周相比,我没有太大变化。它在连接步骤上失败。
我的通用连接代码:
Public Function MyConn() As ADODB.Connection
'Make connection to the DB. Can be called from all macro's
On Error GoTo Message2
Static cnn As ADODB.Connection
Run "BP_Procedures.BP_setparameters"
Set cnn = New ADODB.Connection
cnn.Open "Provider=SQLOLEDB;Data Source= " & Data_source & _
"Initial Catalog= " & Initial_catalog & _
"Integrated Security=SSPI;"
cnn.CursorLocation = adUseClient
Set MyConn = cnn
Exit Function
Message2:
noVPN = True
Exit Function
End Function
在执行 DB 命令的宏中,我有以下代码:
'Make connection
Set cn = MyConn()
cn.CommandTimeout = 0
'insert new lines
insertsql = "INSERT INTO [tbl_Proc_Division_Prod] ([Prdl_ID],[Opp_ID],[Product],[Product_pct]) VALUES ('" & ws.Cells(r, 7) & "'," & ws.Cells(r, 8) & ",'" & ws.Cells(r, 9) & "'," & ws.Cells(r, 10) & ")"
cn.Execute (insertsql)
'Close connection to DB
cn.Close
Set cn = Nothing
Set cn = CloseConn()
关闭连接vba:
Public Function CloseConn() As ADODB.Connection
'This macro is to close the connection to the DB. Can be called from all macro's
Static cnn As ADODB.Connection
Set cnn = Nothing
Set CloseConn = cnn
End Function
同样在 SQL Server 级别(工具 > 选项 > 查询执行),我已将查询执行超时设置为 0。在 SQL Server Management Studio 中,我看到数据库很好,我可以在其上运行查询。
我还能做什么?这些超时开始的原因是什么?
解决方案
推荐阅读
- node.js - 来自 node.js 服务器数据的客户端 D3 折线图
- python - 高斯 Siedel 不收敛
- python - 如何修复 PermissionError: [Errno 13] Permission denied in python?(win10)
- python-3.x - Python 程序不会附加多个值
- java - 如何让 sqlite db 中的光标工作?
- azure - 使用专用终结点时 Azure 弹性作业不起作用
- macos - macOS Catalina 升级后 Go 程序无法运行
- javascript - 如何使用 axios 将数据从 vuejs 表单提交到 zapier webhook?
- rxjs - RxJs 5 of.filter.mapTo 运算符 -> RxJs 6
- javascript - 针对另一个对象数组过滤对象数组?