Solved

How to set connection timeout

Posted on 2012-03-31
4
2,149 Views
Last Modified: 2012-03-31
I am using vb.net and access 2007 database.

I need to change the value of the connection timeout value.

On the msdn for the oledbconnection.ConnectionTimeout Property, but that is ReadOnly.

Can you please give me the code to change the default value of the connection timeout value.

Thanks in advance.
0
Comment
Question by:baabaa_nl
  • 2
4 Comments
 
LVL 9

Accepted Solution

by:
OCDan earned 500 total points
Comment Utility
The default value is 15seconds, if you can't connect to the DB in this time then you likely have other problems that you need to resolve.

However, you can change it here in your VB Code connection string:
Public Sub CreateOleDbConnection()
    Dim myConnString As String = _
       "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;Connect Timeout=30;"
    Dim myConnection As New OleDbConnection(myConnString)
    myConnection.Open()
End Sub
0
 

Author Comment

by:baabaa_nl
Comment Utility
I use a database file on my connectin string.

Below is the kind of connectionstring I use:


Provider=Microsoft.ACE.OLEDB.12.0; DataSource:\\DatabaseWRK\DataFiles\Client.accdb

Could you please insert the above connectinString into the connectinSting that you commented above. Because I am new to the kind of connection string that you have given me.

Thanks in advance.
0
 
LVL 12

Expert Comment

by:Anuradha Goli
Comment Utility
http://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectiontimeout(v=vs.71).aspx


[Visual Basic]
Public Sub CreateSqlConnection()
    Dim myConnection As New SqlConnection()
    myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30"
    myConnection.Open()
End Sub 'CreateSqlConnection

[C#]
public void CreateSqlConnection()
 {
    SqlConnection myConnection = new SqlConnection();
    myConnection.ConnectionString = "Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
    myConnection.Open();
 }
0
 
LVL 9

Assisted Solution

by:OCDan
OCDan earned 500 total points
Comment Utility
"Provider=Microsoft.ACE.OLEDB.12.0; DataSource:\\DatabaseWRK\DataFiles\Client.accdb;Connect Timeout=30;"
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Introduction When developing Access applications, often we need to know whether an object exists.  This article presents a quick and reliable routine to determine if an object exists without that object being opened. If you wanted to inspect/ite…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
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…

771 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now