This documentation is archived and is not being maintained.

OleDbConnection.ConnectionTimeout Property

Gets the time to wait while trying to establish a connection before terminating the attempt and generating an error.

[Visual Basic]
Public Overridable ReadOnly Property ConnectionTimeout As Integer  _
   Implements IDbConnection.ConnectionTimeout
public virtual int ConnectionTimeout {get;}
public: __property virtual int get_ConnectionTimeout();
public function get ConnectionTimeout() : int;

Property Value

The time (in seconds) to wait for a connection to open. The default value is 15 seconds.




Exception Type Condition
ArgumentException The value set is less than 0.


A value of 0 indicates no limit, and should be avoided in a ConnectionString because an attempt to connect will wait indefinitely.


[Visual Basic, C#, C++] The following example creates an OleDbConnection and sets some of its properties in the connection string.

[Visual Basic] 
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)
End Sub

public void CreateOleDbConnection() 
   string myConnString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;Connect Timeout=30;";
   OleDbConnection myConnection = new OleDbConnection(myConnString);

 void CreateOleDbConnection()
    String* myConnString = S"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;Connect Timeout=30;";
    OleDbConnection* myConnection = new OleDbConnection(myConnString);

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

OleDbConnection Class | OleDbConnection Members | System.Data.OleDb Namespace | ConnectionString | Database | DataSource