Export (0) Print
Expand All

SqlConnection.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 a SqlConnection and sets some of its properties in the connection string.

[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();
 }

[C++] 
public:
void CreateSqlConnection() 
 {
    SqlConnection* myConnection = new SqlConnection();
    myConnection->ConnectionString = S"Persist Security Info=False;Integrated Security=SSPI;database=northwind;server=mySQLServer;Connect Timeout=30";
    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, .NET Compact Framework

See Also

SqlConnection Class | SqlConnection Members | System.Data.SqlClient Namespace | ConnectionString | Database | DataSource

Show:
© 2014 Microsoft