Welcome to MSDN Blogs Sign in | Join | Help

MADHU@MICROSOFT BLOG

All About Distributed apps

Syndication

News

Madhu Ponduru works at Microsoft. Everything here, though, is his personal opinion and is not read or approved by Microsoft before it is posted. No warranties or other guarantees will be offered as to the quality of the opinions or anything else offered here.
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();
            }

           

        }

      
    }
}

Published Monday, March 13, 2006 5:38 PM by madhu_ponduru@hotmail.com

Filed under:

Comment Notification

If you would like to receive an email when updates are made to this post, please register here

Subscribe to this post's comments using RSS

Comments

# re: SAMPLE:How to use system.transaction to intiate transaction with oracle @ Thursday, February 28, 2008 10:54 AM

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 time

Ashish

# re: SAMPLE:How to use system.transaction to intiate transaction with oracle @ Thursday, March 06, 2008 7:25 PM

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

madhu_ponduru@hotmail.com

Leave a Comment

(required) 
required 
(required) 

  
Enter Code Here: Required
© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement  
Page view tracker