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. A problem with transactions..

A problem with transactions..

Scheduled Pinned Locked Moved C#
helpcsharpdatabasequestion
4 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.
  • B Offline
    B Offline
    benqazou
    wrote on last edited by
    #1

    Hey, I am having a problem with an application which uses ADO.NET.. Here is the situation: My application is composed of 2 forms : Form1 and Form2, 1- Form1 contains the Main method, and creates a new Form2().. Form1() { ... void SomeMethod(..) { Form2 f = new Form2(.., connectionObj, transactionObject..) f.Show(); } ... } 2- In Form2, I open the connection and start a TRANSACTION, like this: ... connectionObj.Open(); transactionObj= conn.BeginTransaction(); // Some insertions int the database.. ... // I hide the Form2 this.Hide(); I don't commit the transaction in Form2, because I have to wait for another insertion request in Form1 3- When I move to Form1, I try to insert a new line in a certain table, with an SqlCommand, which I try to affect to the transaction, but it doesn't work, I get an error message.. It seems that the modifiation set to the transactionObj are not taken into consideration inside Form1, knowing that it was first declared in this form... Any help please?!

    H 1 Reply Last reply
    0
    • B benqazou

      Hey, I am having a problem with an application which uses ADO.NET.. Here is the situation: My application is composed of 2 forms : Form1 and Form2, 1- Form1 contains the Main method, and creates a new Form2().. Form1() { ... void SomeMethod(..) { Form2 f = new Form2(.., connectionObj, transactionObject..) f.Show(); } ... } 2- In Form2, I open the connection and start a TRANSACTION, like this: ... connectionObj.Open(); transactionObj= conn.BeginTransaction(); // Some insertions int the database.. ... // I hide the Form2 this.Hide(); I don't commit the transaction in Form2, because I have to wait for another insertion request in Form1 3- When I move to Form1, I try to insert a new line in a certain table, with an SqlCommand, which I try to affect to the transaction, but it doesn't work, I get an error message.. It seems that the modifiation set to the transactionObj are not taken into consideration inside Form1, knowing that it was first declared in this form... Any help please?!

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Even after SqlConnection.BeginTransaction(), you have to set the SqlCommand.Transaction with the object returned by the former call.

      Microsoft MVP, Visual C# My Articles

      A 1 Reply Last reply
      0
      • H Heath Stewart

        Even after SqlConnection.BeginTransaction(), you have to set the SqlCommand.Transaction with the object returned by the former call.

        Microsoft MVP, Visual C# My Articles

        A Offline
        A Offline
        Anonymous
        wrote on last edited by
        #3

        Yes I do that everytime before I execute (.ExecuteNonQuery()) any command..the problem is when I return to Form1 (Remember that the transaction is set to a valuer in Form2), I create a new SqlCommand and I write : sqlcommandObj.Transaction = transactionObj; But I always get an error here : //It's an insertion command sqlcommandObj.ExecuteNonQuery();

        H 1 Reply Last reply
        0
        • A Anonymous

          Yes I do that everytime before I execute (.ExecuteNonQuery()) any command..the problem is when I return to Form1 (Remember that the transaction is set to a valuer in Form2), I create a new SqlCommand and I write : sqlcommandObj.Transaction = transactionObj; But I always get an error here : //It's an insertion command sqlcommandObj.ExecuteNonQuery();

          H Offline
          H Offline
          Heath Stewart
          wrote on last edited by
          #4

          It would be helpful if you told us what the exception type and message were, perhaps even a stack trace. Would you just tell a doctor that you have a pain without specifying where?

          Microsoft MVP, Visual C# My Articles

          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