System.Data.SqlClient Namespace SqlConnection Class
Rolls back a transaction from being applied to the database.
[ VB ]
Overloads Overrides Public Sub RollbackTransaction ( )
[ C# ]
public override void RollbackTransaction ( );
[ C++ ]
public: void RollbackTransaction ( );
[ JScript ]
public override function RollbackTransaction ( )
Exception Type |
Condition |
Exception |
An error occured while trying to execute the transaction. |
The transaction can only be rolled back from a pending state ( after BeginTransaction has been called, but before CommitTransaction is called ).
Notes to Inheritors: When overriding RollbackTransaction in a derived class, be sure to call the base class's RollbackTransaction method.
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 ( );
myConn.RollbackTransaction ( );
myConn.Close ( );
}
SqlConnection Members SqlConnection.RollbackTransaction Overload List CommitTransaction SaveTransaction BeginTransaction