Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Query timeout expired when trying to run a short procedure

Tags:

excel

vba

ado

Here's my connection string:

Global Const strConn As String = _
    "PROVIDER=SQLNCLI10;" & _
    "P-SSWORD=blahblah;" & _
    "USER ID=blahblah;" & _
    "INITIAL CATALOG=blah;" & _
    "DATA SOURCE=blah;" & _
    "CONNECT TIMEOUT=0;" & _
    "COMMAND TIMEMOUT=0" & _
    "PACKET SIZE=4096;"

And here is the simple code:

Sub MoveDataUsingADO()

Dim cn As Object
Dim cm As Object
Dim rs As Object

    'get in touch with the server
    'Create ado objects.
Set cn = CreateObject("ADODB.Connection")
cn.connectiontimeout = 0
cn.Open strConn
cn.CommandTimeout = 0

Set cm = CreateObject("ADODB.Command")
Set cm.ActiveConnection = cn
cm.CommandType = 4 'adCmdStoredProc

Set rs = CreateObject("ADODB.Recordset")
Set rs.ActiveConnection = cn


cm.CommandText = "WH.dbo.ourProcName"
With 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)).ClearContents
End With
With 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 connection
End With
...
...

At the point marked above I get the following error:

enter image description here

I don't understand - the procedure takes 55 seconds to run and throughout my vba I have set timeouts to 0... I thought this forced them to not expire?

like image 601
whytheq Avatar asked Nov 03 '13 22:11

whytheq


1 Answers

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.

like image 143
Simon1979 Avatar answered Oct 16 '22 13:10

Simon1979