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. General Programming
  3. C#
  4. ADO.NET cross-base transactions

ADO.NET cross-base transactions

Scheduled Pinned Locked Moved C#
csharpdatabasedebugginghelpquestion
7 Posts 4 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.
  • Y Offline
    Y Offline
    Yoyosch
    wrote on last edited by
    #1

    I made a simple transaction using ADO.NET: SqlTransaction tn; SqlConnection cn = new SqlConnection(/*connection string to 'Database1'*/); try { if (cn.State != ConnectionState.Open) { cn.Open(); } } catch (SqlException ex) { Debug.Assert(false, ex.ToString()); } tn = cn.BeginTransaction(); SqlCommand cmd2 = ... This works nicely. However I would like to make some update statement in other database - 'Database2'. Is it possible to do that inside one ADO.NET transaction? If so, how? Thank you for help in advance.

    realJSOPR M 2 Replies Last reply
    0
    • Y Yoyosch

      I made a simple transaction using ADO.NET: SqlTransaction tn; SqlConnection cn = new SqlConnection(/*connection string to 'Database1'*/); try { if (cn.State != ConnectionState.Open) { cn.Open(); } } catch (SqlException ex) { Debug.Assert(false, ex.ToString()); } tn = cn.BeginTransaction(); SqlCommand cmd2 = ... This works nicely. However I would like to make some update statement in other database - 'Database2'. Is it possible to do that inside one ADO.NET transaction? If so, how? Thank you for help in advance.

      realJSOPR Offline
      realJSOPR Offline
      realJSOP
      wrote on last edited by
      #2

      Delete your prior message before someone responds to it.

      .45 ACP - because shooting twice is just silly
      -----
      "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
      -----
      "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

      Y 1 Reply Last reply
      0
      • Y Yoyosch

        I made a simple transaction using ADO.NET: SqlTransaction tn; SqlConnection cn = new SqlConnection(/*connection string to 'Database1'*/); try { if (cn.State != ConnectionState.Open) { cn.Open(); } } catch (SqlException ex) { Debug.Assert(false, ex.ToString()); } tn = cn.BeginTransaction(); SqlCommand cmd2 = ... This works nicely. However I would like to make some update statement in other database - 'Database2'. Is it possible to do that inside one ADO.NET transaction? If so, how? Thank you for help in advance.

        M Offline
        M Offline
        Mirko1980
        wrote on last edited by
        #3

        You can include your two queries into a TransactionScope. The framework will automatically create a distribute transaction between the two databases. Keep in mind that your infrastructure must be configured to allow so (see Configuring MS DTC).

        Y P 2 Replies Last reply
        0
        • realJSOPR realJSOP

          Delete your prior message before someone responds to it.

          .45 ACP - because shooting twice is just silly
          -----
          "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
          -----
          "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

          Y Offline
          Y Offline
          Yoyosch
          wrote on last edited by
          #4

          dont make rubish on the forum

          realJSOPR 1 Reply Last reply
          0
          • M Mirko1980

            You can include your two queries into a TransactionScope. The framework will automatically create a distribute transaction between the two databases. Keep in mind that your infrastructure must be configured to allow so (see Configuring MS DTC).

            Y Offline
            Y Offline
            Yoyosch
            wrote on last edited by
            #5

            Thank you very much for help

            1 Reply Last reply
            0
            • M Mirko1980

              You can include your two queries into a TransactionScope. The framework will automatically create a distribute transaction between the two databases. Keep in mind that your infrastructure must be configured to allow so (see Configuring MS DTC).

              P Offline
              P Offline
              PIEBALDconsult
              wrote on last edited by
              #6

              I never knew that. I have a few places where that may be beneficial.

              1 Reply Last reply
              0
              • Y Yoyosch

                dont make rubish on the forum

                realJSOPR Offline
                realJSOPR Offline
                realJSOP
                wrote on last edited by
                #7

                Yoyosch wrote:

                dont make rubish on the forum

                Look, retard... You posted the same message twice. I wanted you to delete your first message before someone replied to it because once it's replied to, it can't be deleted. Now, someone's replied to it and it has become the "rubbish" that you are so clearly averse to.

                .45 ACP - because shooting twice is just silly
                -----
                "Why don't you tie a kerosene-soaked rag around your ankles so the ants won't climb up and eat your candy ass..." - Dale Earnhardt, 1997
                -----
                "The staggering layers of obscenity in your statement make it a work of art on so many levels." - J. Jystad, 2001

                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