gpt4 book ai didi

excel - 运行时错误 '-2147217871 (80040e31)' : Query timeout expired

转载 作者:行者123 更新时间:2023-12-02 14:31:32 29 4
gpt4 key购买 nike

当我尝试运行这个大查询时,会出现此错误。较小的查询则不然。我已将连接超时设置为 0,但这没有帮助。看起来连接成功了,但它卡在了代码的 .Open 部分。感谢您的帮助。

Public Sub dbConnectTDaY()
Dim cn As ADODB.Connection
Dim Rec_set As ADODB.Recordset
Dim MyConn, varSQL As String
Dim Rw As Long, Col As Long, c As Long
Dim MyField, Location As Range
Dim i As Integer

Dim strSQL As String
Dim strStDt As String
Dim strEnDt As String
strStDt = ThisWorkbook.Worksheets("xxx").Range("B6").Value
strEnDt = ThisWorkbook.Worksheets("xxx").Range("B5").Value
Set cn = New ADODB.Connection
Set Rec_set = New ADODB.Recordset
Set Location = [A2]
Rw = Location.Row
Col = Location.Column
c = Col

strSQL = ""
strSQL = strSQL & "SELECT gp.cnt"
strSQL = strSQL & ",gp.pod"
strSQL = strSQL & ",gp.grp_paddsa"
strSQL = strSQL & ",gp.grp_rasdd"
' etc.........



cn.ConnectionTimeout = 0 'To wait till the query finishes without generating error

cn.Open "DSN=#EDWP;Databasename=INTY;Uid=XXXXX;Pwd=XXXXX;"


If cn.State = adStateOpen Then 'If connection is success, continue 'Check for errors...

Rec_set.Open strSQL, cn 'Issue SQL statement
For i = 0 To Rec_set.Fields.Count - 1
ActiveSheet.Cells(1, i + 1) = Rec_set.Fields(i).Name
Next i
Do Until Rec_set.EOF
For Each MyField In Rec_set.Fields
Cells(Rw, c) = MyField
c = c + 1
Next MyField
Rec_set.MoveNext
Rw = Rw + 1
c = Col
Loop
End If
Rec_set.Close
cn.Close

End Sub

最佳答案

cn.ConnectionTimeout = 0 仅影响连接超时。

您还想设置CommandTimeout

关于excel - 运行时错误 '-2147217871 (80040e31)' : Query timeout expired,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32612164/

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