1. Overview of the OracleTransaction Class (from MSDN)
The application creates OracleTransaction objects by calling BeginTransaction against the OracleConnection object. Performs all subsequent operations associated with the transaction (for example, committing or aborting the transaction) on the OracleTransaction object. The members of the example oracletransaction are mainly: property: Connection, which specifies the OracleConnection object associated with the transaction; IsolationLevel, which specifies the Isola of the transaction Tionlevel; enumeration type, used for locking things, with values chaos, readcommited, readuncommited, RepeatableRead, Serializable, Unspecified. Method: Commit, commit SQL database transaction, Rollback, ROLLBACK transaction from suspended state;
The following example creates a OracleConnection and a oracletransaction. It also demonstrates how to use the BeginTransaction, Commit, and Rollback methods.
[C #]
public void Runoracletransaction (String myconnstring)
{
OracleConnection myconnection = new OracleConnection (myConnString);
Myconnection.open (); OracleCommand mycommand = Myconnection.createcommand ();
OracleTransaction Mytrans; Start a local transaction
Mytrans = Myconnection.begintransaction (isolationlevel.readcommitted);
Assign transaction object for a pending local transaction
Mycommand.transaction = Mytrans;
Try
{
myCommand.CommandText = "INSERT into Dept (DeptNo, dname, Loc) VALUES (' technology ', ' DENVER ')";
Mycommand.executenonquery ();
myCommand.CommandText = "INSERT into Dept (DeptNo, dname, Loc) VALUES (' ENGINEERING ', ' KANSAS city ')";
Mycommand.executenonquery ();
Mytrans.commit ();
Console.WriteLine ("Both Records is written to database.");
}
catch (Exception e)
{
Mytrans.rollback ();
Console.WriteLine (E.tostring ());
Console.WriteLine ("Neither record was written to database.");
}
Finally
{
Myconnection.close ();
}
}
Using OracleTransaction in C #