Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

How to set connection timeout

Posted on 2012-03-31
4
Medium Priority
?
2,997 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 2000 total points
ID: 37790662
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
ID: 37790726
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
ID: 37790728
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 2000 total points
ID: 37790729
"Provider=Microsoft.ACE.OLEDB.12.0; DataSource:\\DatabaseWRK\DataFiles\Client.accdb;Connect Timeout=30;"
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Access custom database properties are useful for storing miscellaneous bits of information in a format that persists through database closing and reopening.  This article shows how to create and use them.
We live in a world of interfaces like the one in the title picture. VBA also allows to use interfaces which offers a lot of possibilities. This article describes how to use interfaces in VBA and how to work around their bugs.
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

886 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