Export (0) Print
Expand All

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

Implements

IDbConnection.ConnectionTimeout

Exceptions

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

Remarks

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.

Example

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

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

[C++] 
public:
    void CreateOdbcConnection()
    {
        String* myConnString = S"DRIVER= {SQL Server};SERVER=MyServer;Trusted_connection=yes;DATABASE=northwind;";
        OdbcConnection* myConnection = new OdbcConnection(myConnString);
        myConnection->ConnectionTimeout = 60;
        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

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

Show:
© 2014 Microsoft