using System;
using System.Data;
using System.Data.OleDb;
class TransactionExample
{
static void Main()
{
string ConStr = ("Provider=MSDAORA;data source=OracleJava;User ID=scott;Password=tiger");
OleDbConnection Conn = new OleDbConnection(ConStr);
Conn.Open();
OleDbTransaction trans;
trans = Conn.BeginTransaction();
Console.WriteLine("{0}", trans.IsolationLevel); //IsolationLevel 출력.
try
{
string sqladd = "INSERT INTO emp (empno, ename) VALUES (3333, '3돌이')";
OleDbCommand cmdAdd = new OleDbCommand(sqladd, Conn);
string sqladd1 = "INSERT INTO emp (empno, ename) VALUES (4444, '4돌이')";
OleDbCommand cmdAdd1 = new OleDbCommand(sqladd1, Conn);
cmdAdd.Transaction = trans;
cmdAdd1.Transaction = trans;
int rowsadded1 = cmdAdd1.ExecuteNonQuery();
int rowsadded = cmdAdd.ExecuteNonQuery();
Console.WriteLine("Number of rows added: " + rowsadded);
Console.WriteLine("Number of rows added: " + rowsadded1);
trans.Commit();
Console.WriteLine("WRITE OK~~~");
}
catch(Exception e)
{
trans.Rollback();
Console.WriteLine(e.ToString());
}
finally
{
Conn.Close();
Console.Write("\n");
Console.WriteLine("Connection is closed.");
}
}
}
==========================================
[결과]
ReadCommitted
Number of rows added: 1
Number of rows added: 1
WRITE OK~~~
Connection is closed.
댓글 없음:
댓글 쓰기