System.Data.SqlClient Namespace SqlConnection Class
Rolls back a database transaction with the transaction name.
[ VB ]
Overloads Public Sub RollbackTransaction ( _
ByVal transactionName As String _
)
[ C# ]
void RollbackTransaction (
string transactionName
);
[ C++ ]
public: void RollbackTransaction (
String* transactionName
);
[ JScript ]
public function RollbackTransaction (
transactionName : String
);
- transactionName
- The name of the transaction or save point to rollback.
There are restrictions when using transactionName with nested transactions: Only the outermost transaction name is registered, so attempting to roll back to a named inner transaction will generate an error.
The transaction can only be rolled back from a pending state ( after BeginTransaction has been called, but before CommitTransaction is called ).
The following example initializes an SqlConnection, opens it, begins a transaction, rollsback the transaction, then closes the connection. To accomplish this, the method is passed an SQL connection string to use to connect to the data source.
void RunSqlTransaction ( string strConn ) {
SqlConnection myConn = new SqlConnection ( strConn );
myConn.Open ( );
myConn.BeginTransaction ( "SampleTransaction" );
myConn.RollbackTransaction ( "SampleTransaction" );
myConn.Close ( );
}
SqlConnection Members SqlConnection.RollbackTransaction Overload List CommitTransaction SaveTransaction BeginTransaction