Starts a transaction at the data source.
Assembly: System.Data (in System.Data.dll)
A transaction is currently active. Parallel transactions are not supported.
To make sure that the .NET Framework Data Provider for ODBC transaction management model performs correctly, avoid using other transaction management models, such as those provided by the data source.
If you do not specify an isolation level, the isolation level will be determined by the driver being used. To specify an isolation level with the BeginTransaction method, use the overload that takes the isolevel parameter.
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
Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.