last day (14 days later) » 

8:53 AM
0
Q: ADODB Command.Execute Timeout

iabbottI am seeing a timeout error when running a query from Excel vba The query takes <2 seconds from the SQL Server Management Studio, but from vba the timeout happens at 2 minutes with nothing returned Is there something i am not doing right setting up the Command object? I have noticed that ADODB ...

 
Is my understanding correct that queries run from SQL Server Management Studio and from Excel VBA have the same input parameters and are run against the same database?
 
yes the query is the same, i used the same parameters and the database is the same
 
Did you try to run this query in Excel VBA two times one by one. I'd like to confirm that it always takes 2 minutes to execute it and not only for the first time.
 
It takes longer then 2 mins, i have set that as the timeout and it errors each time. I am changing the timeout to zero to see how long it takes, i will run it a couple of times and get back to you
so 3 runs - 1st took 2min 31, 2nd took 2min 27, 3rd took 2min 35
 
What is your connection string? What library do you use in Excel (e.g. Microsoft ActiveX Data Objects 2.8 Library)?
 
8:56 AM
If svrCon Is Nothing Then
    Set svrCon = New ADODB.Connection
End If

If Not CheckServerConnectionState Then

    conStr = "Provider=SQLOLEDB;Data Source=ussantapps332;" & _
                    "Initial Catalog=Global_OEE_Data_Capture_Dev;User Id=sqluser;Password=*****;"

    ' Open the connection
    svrCon.ConnectionTimeout = 0
    svrCon.Open conStr

End If
and when it is opened, svrCon contains
Provider=SQLOLEDB.1;User ID=sqluser;Initial Catalog=Global_OEE_Data_Capture_Dev;Data Source=ussantapps332;Use Procedure for Prepare=1;Auto Translate=True;Packet Size=4096;Workstation ID=UKASHIABBOTTL7;Use Encryption for Data=False;Tag with column collation when possible=False;
the library is ADO 2.8
 
I used the same library and similar connection string and I see now difference between VBA and SQL Management Studio.
How much data do you try to read from the database?
 
it is pulling out ~8600 rows with 23 fields each
 
I read ~5000 rows with 96 fields each
Is SQL Management Studio on the same machine as VBA script?
 
yes
and the server is remote (i am in UK the server is USA)
 
9:27 AM
Do you have possibility to test this query locally?
 
i am setting up a local database to do that, give me 10 mins
 
10:05 AM
ok so local database it runs at around 1 second
both vba and in management studio
 
10:18 AM
interesting
did you try to use a different provider in VBA? For example SQLNCLI10, SQLNCLI11?
or simply SQLNCLI
 
10:32 AM
huh
SQLNCLI11 takes 3 seconds
i didn't realize i could change that
 
good information
I will write an answer
 
thanks!
and i will update my code :)
 

last day (14 days later) »