This documentation is archived and is not being maintained.

OdbcConnection.ConnectionTimeout Property

Note: This namespace, class, or member is supported only in version 1.1 of the .NET Framework.

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

[Visual Basic]
Public Overridable Property ConnectionTimeout As Integer  _
   Implements IDbConnection.ConnectionTimeout
public virtual int ConnectionTimeout {get; set;}
public: __property virtual int get_ConnectionTimeout();
public: __property void set_ConnectionTimeout(int);
public function get ConnectionTimeout() : int;
public function set 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.


Unlike the .NET Framework data providers for SQL Server and OLE DB, the .NET Framework Data Provider for ODBC does not support setting this property as a connection string value, because it is not a valid ODBC connection keyword. To specify a connection timeout, set the ConnectionTimeout property before calling Open. This is equivalent to setting the ODBC SQLSetConnectAttr SQL_ATTR_LOGIN_TIMOUT attribute.


[Visual Basic, C#, C++] The following example creates an OdbcConnection and sets the ConnectionTimeout property.

[Visual Basic] 
Public Sub CreateOdbcConnection()
     Dim myConnString As String = _
        "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;"
     Dim myConnection As New OdbcConnection(myConnString)
     myConnection.ConnectionTimeout = 60
 End Sub

public void CreateOdbcConnection() 
    string myConnString = "DRIVER={SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
    OdbcConnection myConnection = new OdbcConnection(myConnString);
    myConnection.ConnectionTimeout = 60;

    void CreateOdbcConnection()
        String* myConnString = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
        OdbcConnection* myConnection = new OdbcConnection(myConnString);
        myConnection->ConnectionTimeout = 60;

[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

OdbcConnection Class | OdbcConnection Members | System.Data.Odbc Namespace | ConnectionString | Database