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();
}
}
}
}
Comments
Anonymous
February 28, 2008
Does oracle participate in the ambient transaction by which i mean does it promote itself to Distributed transaction. Also why does it slow down the performance when transacope is used for first timeAnonymous
March 06, 2008
If you have any question related to MSDTC or system.Transactions,please send your question to DTC forum http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=388&SiteID=1