Using OracleTransaction in C #

Source: Internet
Author: User
Tags dname oracleconnection

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 #

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.