Query timeout expired when trying to run a short procedure Query timeout expired when trying to run a short procedure vba vba

Query timeout expired when trying to run a short procedure


Have you tried setting the time out explicitly on the command?

cm.CommandTimeout = 0

Rather than setting it on the connection. I think the connection timeout deals with how long it lets you try to establish a connection before it rejects while the command timeout is how long you command has to execute.


Do you have some idea how long it should take your query to execute? Might there be a different problem than the timeout period?

You should try setting the timeout on the command object like this:

cm.CommandText = "WH.dbo.ourProcName"cm.CommandTimeout = 120With wb.Sheets("Data")    .Activate    .Range(.Cells(2, 1), .Cells(.Cells(.Rows.Count, 2).End(Excel.xlUp).Row + 1, .Cells(1, .Columns.Count).End(Excel.xlToLeft).Column)).ClearContentsEnd WithWith rs    .Open Source:=cm.Execute '<=====errors here===========     wb.Sheets("Data").Cells(wb.Sheets("Data").Rows.Count, 1).End(Excel.xlUp)(2, 1).CopyFromRecordset rs    .Close      'close connectionEnd With