Solved

VBA query times out, ignores connection timeout setting

Posted on 2007-03-17
5
2,247 Views
Last Modified: 2012-06-27
I have a VBA form that is timing out accessing a MS SQL server view. I have two button on this form. On runs a report preview a la the standard wizard setup. The other run code in the form where I open the view and loop through the rows outputting a text transaction file.

The view takes about 1:14 minutes to run. Under File --> Connection --> advanced, I set the timeout to 120 seconds and that took care of the report preview. However, the query coded in my VBA form times out after 30 seconds, regardless of what I set the connection timeout to. Whats up? Here's my query call:

    Dim rs As New ADODB.Recordset

    rs.Open "select * from _vwPaActuaryActive", GetADoConnectString("PA"), adOpenForwardOnly, adLockReadOnly, adCmdText

0
Comment
Question by:jmarkfoley
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
5 Comments
 
LVL 11

Expert Comment

by:andrewbleakley
ID: 18742508
The time you have set is the connection timeout (the time after which it assumes the SQL server is not present if it receives no response). You will need to use an ADODB.Command object and set it's CommandTimeout property as below.

Dim cn as New ADODB.Connection
Dim cmd as New ADODB.Command
Dim rs As New ADODB.Recordset
cn.Open( GetADoConnectString("PA") )
cmd.ActiveConnection = cn
cmd.CommandType = adCmdText
cmd.CommandTimeout = 120
cmd.CommandText = "select * from _vwPaActuaryActive"
rs = cmd.Execute
rs.Close()
0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 18742627
Compiling your example gives me: "Invalid use of property" on the line: rs= cmd.Execute

suggestions?
0
 
LVL 11

Accepted Solution

by:
andrewbleakley earned 500 total points
ID: 18742654
Sorry
Set rs = cmd.Execute
I don't have a VB IDE on this machine

0
 
LVL 1

Author Comment

by:jmarkfoley
ID: 18742769
That did it! Thanks. One of these days I'm going to have to read up on 'set'. Once upon a time, there wasn't a difference between 'a = b' and 'set a = b'.

0
 
LVL 11

Expert Comment

by:andrewbleakley
ID: 18742855
a = b assigns a VALUE to a variable
set a = b assigns an OBJECT to a variable
0

Featured Post

The Eight Noble Truths of Backup and Recovery

How can IT departments tackle the challenges of a Big Data world? This white paper provides a roadmap to success and helps companies ensure that all their data is safe and secure, no matter if it resides on-premise with physical or virtual machines or in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question