Excel VBA: ODBC SQL server driver query timeout expired

后端 未结 3 2009
轻奢々
轻奢々 2021-01-29 01:47

I have the below VBA query used in Excel 2016 that exacutes a MS Sql stored procedure, sometimes it executes smoothly and returns the recordset, but more often I get an error

3条回答
  •  轮回少年
    2021-01-29 02:27

    After some more thought about the question and the comments on my prior answer, here are some additional points. To BitAccesser, cn.CommandTimeout is the same as Connection.CommandTimeout since the originally submitted code had already dimensioned and set the cn object as an ADODB.Connection. Also worth noting is the difference between ConnectionTimeout and CommandTimeout. The connection timeout is network level, while the command timeout is SQL Server level. In this case, even though a ADODB.Command object is instantiated, it isn't used. Another point relates to the connection string. The connection timeout could be referenced in the connection string, but often, is not used. The connection will be defaulted to 15 seconds. So, its worth resetting those attributes explicitly.

        Cn.CommandTimeout = 50
        Cn.ConnectionTimeout = 50
    

提交回复
热议问题