OleDbConnection.ConnectionTimeout 속성

정의

시도를 종료하고 오류를 생성하기 전에 연결하는 동안 대기할 시간(초 단위)을 가져옵니다.

public:
 virtual property int ConnectionTimeout { int get(); };
public:
 property int ConnectionTimeout { int get(); };
public override int ConnectionTimeout { get; }
[System.Data.DataSysDescription("OleDbConnection_ConnectionTimeout")]
public int ConnectionTimeout { get; }
member this.ConnectionTimeout : int
[<System.Data.DataSysDescription("OleDbConnection_ConnectionTimeout")>]
member this.ConnectionTimeout : int
Public Overrides ReadOnly Property ConnectionTimeout As Integer
Public ReadOnly Property ConnectionTimeout As Integer

속성 값

Int32

연결이 열릴 때까지 대기하는 시간(초)입니다. 기본값은 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 해야 합니다.

적용 대상

추가 정보