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
[C#]
public virtual int ConnectionTimeout {get;}
[C++]
public: __property virtual int get_ConnectionTimeout();
[JScript]
public function get ConnectionTimeout() : int;

Property Value

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

Implements

IDbConnection.ConnectionTimeout

Exceptions

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

Remarks

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

Example

[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)
    myConnection.Open()
End Sub

[C#] 
public void CreateOleDbConnection() 
{
   string myConnString = "Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;Connect Timeout=30;";
   OleDbConnection myConnection = new OleDbConnection(myConnString);
   myConnection.Open();
}

[C++] 
public:
 void CreateOleDbConnection()
 {
    String* myConnString = S"Provider=SQLOLEDB;Data Source=localhost;Initial Catalog=Northwind;Integrated Security=SSPI;Connect Timeout=30;";
    OleDbConnection* myConnection = new OleDbConnection(myConnString);
    myConnection->Open();
 }

[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.

Requirements

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

Show: