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
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