ADO.NET cross-base transactions
-
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. -
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.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 -
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.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).
-
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 -
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).
-
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).
I never knew that. I have a few places where that may be beneficial.
-
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