Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. oracle transaction with multi OracleConnection c # ?

oracle transaction with multi OracleConnection c # ?

Scheduled Pinned Locked Moved Database
questiondatabaseoraclehelp
3 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    User 10565015
    wrote on last edited by
    #1

    I have 2 database,
    oracle transaction with multi OracleConnection c #
    Table 1 in the database 1

    Table 2 in the database 2
    When save new data to Table 1, I want to save the data in Table 2 in the database 2
    How can I do this in oracle transaction

    using (OracleConnection connection1 = new OracleConnection(connectionstring1) )// databsse1
    {OracleConnection connection2=new OracleConnection (connectionstring2);//database2
    connection.Open();

                OracleCommand command = connection.CreateCommand();
                OracleTransaction trans;
                
                trans = connection.BeginTransaction(IsolationLevel.ReadCommitted);
                command.Transaction = trans;
                try
    

    {
    command.Text =sql1//insert into table1 in database1
    command.ExecuteNonQuery();
    command.Text =sql2//insert into table2 in database2
    //Here the problem by looking for a solution
    How can I do that
    trans.Commit();
    }
    catch (Exception ex)
    {

                    trans.Rollback();
                }
            }
    
    L S 2 Replies Last reply
    0
    • U User 10565015

      I have 2 database,
      oracle transaction with multi OracleConnection c #
      Table 1 in the database 1

      Table 2 in the database 2
      When save new data to Table 1, I want to save the data in Table 2 in the database 2
      How can I do this in oracle transaction

      using (OracleConnection connection1 = new OracleConnection(connectionstring1) )// databsse1
      {OracleConnection connection2=new OracleConnection (connectionstring2);//database2
      connection.Open();

                  OracleCommand command = connection.CreateCommand();
                  OracleTransaction trans;
                  
                  trans = connection.BeginTransaction(IsolationLevel.ReadCommitted);
                  command.Transaction = trans;
                  try
      

      {
      command.Text =sql1//insert into table1 in database1
      command.ExecuteNonQuery();
      command.Text =sql2//insert into table2 in database2
      //Here the problem by looking for a solution
      How can I do that
      trans.Commit();
      }
      catch (Exception ex)
      {

                      trans.Rollback();
                  }
              }
      
      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Create a new Command with connection2 and execute your sql2 in the new command. Don't forget to set the same transaction for the new command.

      1 Reply Last reply
      0
      • U User 10565015

        I have 2 database,
        oracle transaction with multi OracleConnection c #
        Table 1 in the database 1

        Table 2 in the database 2
        When save new data to Table 1, I want to save the data in Table 2 in the database 2
        How can I do this in oracle transaction

        using (OracleConnection connection1 = new OracleConnection(connectionstring1) )// databsse1
        {OracleConnection connection2=new OracleConnection (connectionstring2);//database2
        connection.Open();

                    OracleCommand command = connection.CreateCommand();
                    OracleTransaction trans;
                    
                    trans = connection.BeginTransaction(IsolationLevel.ReadCommitted);
                    command.Transaction = trans;
                    try
        

        {
        command.Text =sql1//insert into table1 in database1
        command.ExecuteNonQuery();
        command.Text =sql2//insert into table2 in database2
        //Here the problem by looking for a solution
        How can I do that
        trans.Commit();
        }
        catch (Exception ex)
        {

                        trans.Rollback();
                    }
                }
        
        S Offline
        S Offline
        Simon_Whale
        wrote on last edited by
        #3

        Just a thought. if the tables structures are the same have you not thought about using database triggers?[^]

        Every day, thousands of innocent plants are killed by vegetarians. Help end the violence EAT BACON

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups