A problem with transactions..
-
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?! -
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?!Even after
SqlConnection.BeginTransaction()
, you have to set theSqlCommand.Transaction
with the object returned by the former call.Microsoft MVP, Visual C# My Articles
-
Even after
SqlConnection.BeginTransaction()
, you have to set theSqlCommand.Transaction
with the object returned by the former call.Microsoft MVP, Visual C# My Articles
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();
-
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();
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