• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 899
  • Last Modified:

How to set the query timout property?

How can I set the query timeout property in my project?  I am trying the following:

    Dim cn As OleDbConnection
    set    cn.QueryTimeout = 120
   
    Const strCN As String = "Provider=SQLNCLI10.1;Integrated Security=SSPI;Persist Security Info=False;User ID='';Initial Catalog=LH1_Replicate;Data Source=BS-120471\SQLEXPRESS;Initial File Name=''; Connect Timeout=60000; Server SPN=''"

but I receive a sintax error on the "set".  

I am a beginner using Visual Studio 2008

Thank you very much.
0
kgittinger
Asked:
kgittinger
1 Solution
 
Jared_SCommented:
Don't set the timeout on the connection. Go ahead and open your database and then call this sub.

Sub SetTimeout()
      Dim Mydb as Database
      Set Mydb=CurrentDB
      MYdb.QueryTimeout=120
  End Sub

Open in new window


You might see if there is any way to make your query more efficient as an alternative solution.
0
 
Luis PérezSoftware Architect in .NetCommented:
After you open your OleDBConnection, you probably are going to use OleDbCommands to make your queries. Then you can use the CommandTimeout property of the OledbCommand object.

Dim cmd As OleDbCommand = New OleDbCommand(...)
cmd.CommandTimeout = 120

Open in new window


Hope that helps.
0
 
kgittingerAuthor Commented:
Thank you.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now