ADODB query timeout
Asked Answered
G

3

21

I am trying to open a query, which is timing out. I have tried setting the timeout property, but it doesn't seem to want to accept it.

The query takes 34 seconds to execute using MS-SQL Server Management window (SQL Server 2005), so I know I need to increase the timeout.

Current code:

Public Function retRecordSet(StrSQL)
Dim cmd ' as new ADODB.Command
Dim rs 'As New ADODB.Recordset

Set cmd = CreateObject("ADODB.Command")
Set rs = CreateObject("ADODB.Recordset")

cmd.ActiveConnection = CurrentProject.Connection
cmd.CommandText = StrSQL
cmd.CommandTimeout = 0
Set rs = cmd.Execute

Set retRecordSet = rs
End Function

I have also tried setting the timeout of the connection itself CurrentProject.Connection.CommandTimeout = 120, but if I query the value right after this command, it remains at 30

Connection properties:

Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=MyServer;Integrated Security=SSPI;Initial Catalog=MyDatabase;Data Provider=SQLOLEDB.1

Data Source Object Threading Model = 1
Multiple Results = 3
Multiple Parameter Sets = False
SQL Support = 283
Catalog Location = 1
Catalog Term = database
Catalog Usage = 15
Rowset Conversions on Command = True
Extended Properties = 
Cache Authentication = True
Encrypt Password = 
Persist Encrypted = 
Persist Security Info = False
Asynchronous Processing = 0
Connect Timeout = 600
Protection Level = 
Prompt = 4
Mode = 
Location = 
Locale Identifier = 1033
Impersonation Level = 
Window Handle = 
Data Source = MyServer
User ID = 
Password = 
Integrated Security = SSPI
Mask Password = 
Initial Catalog = MyDatabase
Lock Owner = 
Bind Flags = 
General Timeout = 0
Data Provider = SQLOLEDB.1
Autocommit Isolation Levels = 4096
Unique Reshape Names = False
Gastritis answered 10/7, 2013 at 15:19 Comment(6)
Take a look at this blog post: codingjourney.blogspot.com/2008/11/…Ballance
@HK1, you'll see I set the command timeout on the ADODB Command to 0 (Infinite timeout)Gastritis
Not sure why the 30 second timeout remains, seems very strange. What happens if you call 'rs.open cmd' instead of 'set rs = cmd.execute' passing in your command object as the source. Just curious if you run into the same issue there?Germanophobe
How is your connection setup? When I use ADO connections I always use explicit connections that I create so I'm not accustomed to using CurrentProject.Connection. Is this an ADP?Ballance
@HK1, yes, it's an ADP (and I can't change that)Gastritis
@SeanCheshire just out of interest - does CommandTimeout = 0 mean to set no time out?Californium
P
34

Not sure if you already got over the problem but I had the same issue. I'm doing it with Recordset.Open SQL_String, Connection.

And before that I just set the timeout property, not on the Recordset or Command but on the Connection object:

Connection.CommandTimeout = 0
Proxy answered 30/4, 2014 at 7:30 Comment(0)
D
16

from http://codingjourney.blogspot.com/2008/11/ado-connection-timeout-command-or.html

The Solution

You must also set the commandTimeout property on the ADODB.Command or ADODB.Recordset being used. Otherwise those objects will use the default time limit of 30 seconds because they do not inherit the time limit from the associated ADODB.Connection instance.

Example Using VBScript in ASP 3:

set con = createObject("ADODB.Connection")
con.open connectionString
con.commandTimeout = 60
set command = createObject("ADODB.Command")
command.activeConnection = con
command.commandType = adCmdText
command.commandText = sql
command.commandTimeout = 60
command.execute
response.write command.commandTimeout 'This is now 60 seconds.
Dielectric answered 28/6, 2018 at 7:19 Comment(1)
About this: "You must also set the commandTimeout property on the ADODB.Command or ADODB.Recordset being used." I'm not seeing a CommandTimeout property or method on the ADODB.Recordset object.Sulfapyridine
H
1

For OLEDB do you not need to specify the timout on the connection :-

Provider=Microsoft.Access.OLEDB.10.0;Persist Security Info=False;Data Source=MyServer;Integrated Security=SSPI;Initial Catalog=MyDatabase;Data Provider=SQLOLEDB.1;Connect Timeout=30

Halbeib answered 11/7, 2013 at 8:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.