OleDbConnection.ConnectionTimeout 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
在嘗試建立連線時,會獲得等待時間(以幾秒計),然後才終止嘗試並產生錯誤。
public:
property int ConnectionTimeout { int get(); };
public:
virtual property int ConnectionTimeout { int get(); };
[System.Data.DataSysDescription("OleDbConnection_ConnectionTimeout")]
public int ConnectionTimeout { get; }
public override int ConnectionTimeout { get; }
[<System.Data.DataSysDescription("OleDbConnection_ConnectionTimeout")>]
member this.ConnectionTimeout : int
member this.ConnectionTimeout : int
Public ReadOnly Property ConnectionTimeout As Integer
Public Overrides ReadOnly Property ConnectionTimeout As Integer
屬性值
等待連線開啟的時間也就是幾秒鐘。 預設值為 15 秒。
實作
- 屬性
例外狀況
值集合小於 0。
範例
以下範例建立 , OleDbConnection 並在連接字串中設定其部分屬性。
// The connectionString argument contains the Connect Timeout
// keywords, as follows: "... ;Connect Timeout=30;"
public void InsertRow(string connectionString, string insertSQL)
{
using (OleDbConnection connection = new OleDbConnection(connectionString))
{
// The insertSQL string contains a SQL statement that
// inserts a new row in the source table.
OleDbCommand command = new OleDbCommand(insertSQL);
// Set the Connection to the new OleDbConnection.
command.Connection = connection;
// Open the connection and execute the insert command.
try
{
connection.Open();
command.ExecuteNonQuery();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
}
}
' The connectionString argument contains the Connect Timeout
' keywords, as follows: "... ;Connect Timeout=30;"
Public Sub InsertRow(ByVal connectionString As String, _
ByVal insertSQL As String)
Using connection As New OleDbConnection(connectionString)
' The insertSQL string contains a SQL statement that
' inserts a new row in the source table.
Dim command As New OleDbCommand(insertSQL)
' Set the Connection to the new OleDbConnection.
command.Connection = connection
' Open the connection and execute the insert command.
Try
connection.Open()
command.ExecuteNonQuery()
Catch ex As Exception
Console.WriteLine(ex.Message)
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
備註
值為 0 表示無限制,應避免在 中 ConnectionString 嘗試連線,因為嘗試連線會無限期等待。