OdbcConnection.BeginTransaction 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
데이터 원본에서 트랜잭션을 시작합니다.
오버로드
| Name | Description |
|---|---|
| BeginTransaction() |
데이터 원본에서 트랜잭션을 시작합니다. |
| BeginTransaction(IsolationLevel) |
지정된 IsolationLevel 값을 사용하여 데이터 원본에서 트랜잭션을 시작합니다. |
BeginTransaction()
데이터 원본에서 트랜잭션을 시작합니다.
public:
System::Data::Odbc::OdbcTransaction ^ BeginTransaction();
public System.Data.Odbc.OdbcTransaction BeginTransaction();
member this.BeginTransaction : unit -> System.Data.Odbc.OdbcTransaction
override this.BeginTransaction : unit -> System.Data.Odbc.OdbcTransaction
Public Function BeginTransaction () As OdbcTransaction
반품
새 트랜잭션을 나타내는 개체입니다.
예외
트랜잭션이 현재 활성화되어 있습니다. 병렬 트랜잭션은 지원되지 않습니다.
예제
다음 예제에서는 및 .를 OdbcConnectionOdbcTransaction만듭니다. 또한 , Commit및 Rollback 메서드를 BeginTransaction사용하는 방법을 보여 줍니다.
public static void ExecuteTransaction(string connectionString)
{
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
// Set the Connection to the new OdbcConnection.
command.Connection = connection;
// Open the connection and execute the transaction.
try
{
connection.Open();
// Start a local transaction
transaction = connection.BeginTransaction();
// Assign transaction object for a pending local transaction.
command.Connection = connection;
command.Transaction = transaction;
// Execute the commands.
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
command.ExecuteNonQuery();
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
command.ExecuteNonQuery();
// Commit the transaction.
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
try
{
// Attempt to roll back the transaction.
transaction.Rollback();
}
catch
{
// Do nothing here; transaction is not active.
}
}
// The connection is automatically closed when the
// code exits the using block.
}
}
Public Sub ExecuteTransaction(ByVal connectionString As String)
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand()
Dim transaction As OdbcTransaction
' Set the Connection to the new OdbcConnection.
command.Connection = connection
' Open the connection and execute the transaction.
Try
connection.Open()
' Start a local transaction.
transaction = connection.BeginTransaction()
' Assign transaction object for a pending local transaction.
command.Connection = connection
command.Transaction = transaction
' Execute the commands.
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
command.ExecuteNonQuery()
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
command.ExecuteNonQuery()
' Commit the transaction.
transaction.Commit()
Console.WriteLine("Both records are written to database.")
Catch ex As Exception
Console.WriteLine(ex.Message)
' Try to rollback the transaction
Try
transaction.Rollback()
Catch
' Do nothing here; transaction is not active.
End Try
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
설명
트랜잭션을 커밋하거나 롤백하려면 명시적으로 또는 Rollback 메서드를 Commit 사용해야 합니다.
.NET Framework Data Provider ODBC 트랜잭션 관리 모델이 올바르게 수행되도록 하려면 데이터 원본에서 제공하는 것과 같은 다른 트랜잭션 관리 모델을 사용하지 않도록 합니다.
메모
격리 수준을 지정하지 않으면 격리 수준은 사용 중인 드라이버에 의해 결정됩니다. 메서드를 사용하여 격리 수준을 BeginTransaction 지정하려면 매개 변수를 사용하는 오버로드를 isolevel 사용합니다.
추가 정보
적용 대상
BeginTransaction(IsolationLevel)
지정된 IsolationLevel 값을 사용하여 데이터 원본에서 트랜잭션을 시작합니다.
public:
System::Data::Odbc::OdbcTransaction ^ BeginTransaction(System::Data::IsolationLevel isolevel);
public System.Data.Odbc.OdbcTransaction BeginTransaction(System.Data.IsolationLevel isolevel);
member this.BeginTransaction : System.Data.IsolationLevel -> System.Data.Odbc.OdbcTransaction
override this.BeginTransaction : System.Data.IsolationLevel -> System.Data.Odbc.OdbcTransaction
Public Function BeginTransaction (isolevel As IsolationLevel) As OdbcTransaction
매개 변수
- isolevel
- IsolationLevel
이 연결의 트랜잭션 격리 수준입니다. 격리 수준을 지정하지 않으면 드라이버의 기본 격리 수준이 사용됩니다.
반품
새 트랜잭션을 나타내는 개체입니다.
예외
트랜잭션이 현재 활성화되어 있습니다. 병렬 트랜잭션은 지원되지 않습니다.
예제
다음 예제에서는 및 .를 OdbcConnectionOdbcTransaction만듭니다. 또한 , Commit및 Rollback 메서드를 BeginTransaction사용하는 방법을 보여 줍니다.
public static void ExecuteTransaction(string connectionString)
{
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
OdbcCommand command = new OdbcCommand();
OdbcTransaction transaction = null;
// Set the Connection to the new OdbcConnection.
command.Connection = connection;
// Open the connection and execute the transaction.
try
{
connection.Open();
// Start a local transaction
transaction = connection.BeginTransaction();
// Assign transaction object for a pending local transaction.
command.Connection = connection;
command.Transaction = transaction;
// Execute the commands.
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')";
command.ExecuteNonQuery();
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')";
command.ExecuteNonQuery();
// Commit the transaction.
transaction.Commit();
Console.WriteLine("Both records are written to database.");
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
try
{
// Attempt to roll back the transaction.
transaction.Rollback();
}
catch
{
// Do nothing here; transaction is not active.
}
}
// The connection is automatically closed when the
// code exits the using block.
}
}
Public Sub ExecuteTransaction(ByVal connectionString As String)
Using connection As New OdbcConnection(connectionString)
Dim command As New OdbcCommand()
Dim transaction As OdbcTransaction
' Set the Connection to the new OdbcConnection.
command.Connection = connection
' Open the connection and execute the transaction.
Try
connection.Open()
' Start a local transaction.
transaction = connection.BeginTransaction()
' Assign transaction object for a pending local transaction.
command.Connection = connection
command.Transaction = transaction
' Execute the commands.
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (100, 'Description')"
command.ExecuteNonQuery()
command.CommandText =
"Insert into Region (RegionID, RegionDescription) VALUES (101, 'Description')"
command.ExecuteNonQuery()
' Commit the transaction.
transaction.Commit()
Console.WriteLine("Both records are written to database.")
Catch ex As Exception
Console.WriteLine(ex.Message)
' Try to rollback the transaction
Try
transaction.Rollback()
Catch
' Do nothing here; transaction is not active.
End Try
End Try
' The connection is automatically closed when the
' code exits the Using block.
End Using
End Sub
설명
트랜잭션을 커밋하거나 롤백하려면 명시적으로 또는 Rollback 메서드를 Commit 사용해야 합니다.
.NET Framework Data Provider ODBC 트랜잭션 관리 모델이 올바르게 수행되도록 하려면 데이터 원본에서 제공하는 것과 같은 다른 트랜잭션 관리 모델을 사용하지 않도록 합니다.