SAMPLE:How to use system.transaction to intiate transaction with oracle
//copy following program into console app and replace connection string and query string
using System;
using System.Collections.Generic;
using System.Text;
using System.Transactions;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
namespace TransClient
{
class Program
{
static void Main(string[] args)
{
ConnectToOracle();
Console.WriteLine("Press any key to quit");
Console.ReadKey();
}
//Try to connect to oracle database
public static void ConnectToOracle()
{
/*
VERSION: windows xp,sp2/.NET 2.0/oracle client 9i/Microsoft oledb provider/oracle oledb provider
NOTE:
incase if data provider can't understand systx,provide COM+/ES context
TransactionOptions to = new TransactionOptions();
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required,to,EnterpriseServicesInteropOption.Full))
*/
//using Microsoft oledb provider
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=MSDAORA.1;User ID=XXX;password=XXX;Data Source=oracleservername;Persist Security
Info=False";
conn.Open();
OleDbCommand cmd = new OleDbCommand("insert into XXX values('5')", conn);
cmd.ExecuteNonQuery
ts.Complete();
}
//using oracle oledb provider
using (TransactionScope ts = new TransactionScope(TransactionScopeOption.Required))
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = "Provider=ORAOLEDB.ORACLE.1;User ID=XXX;password=XXX;Data Source=oracleservername;Persist
Security Info=False";
conn.Open();
OleDbCommand cmd = new OleDbCommand("insert into XXX values('5')", conn);
cmd.ExecuteNonQuery();
ts.Complete();
}
}
}
}