473,394 Members | 1,674 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

using Transactionscope with 2 dbs

When I use transactions with sql server I usually do this...
using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .

and this all works great. But now, I need to stretch the transaction across
to sql databases using two different connections i.e.

using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .
{
work
work
}//dispose of connection

using (SqlConnection2, - new SqlConnection . . . . .
{
work
work
}//dispose of connection
scope.Complete();
}//dispose of transaction scope

Is this supposed to work this way? Can a TransactionScope stretch across
many databases and cause a rollback of them all if an exception occurs?

--
Regards,
Gary Blakely
Jun 27 '08 #1
2 2608
try something like

try
{
using(TransactionScope scope = new TransactionScope())
{
using(conn1 = new SqlConnection(strConnection1))
{
Work1();

using(conn2 = new SqlConnection(strConnection2))
{
Work2();
}
}
scope.Complete();
}
}
catch(TransactionAbortedException ex)
{
ErrorHandler(ex);
}
--
Misbah Arefin
https://mcp.support.microsoft.com/profile/MISBAH.AREFIN
http://www.linkedin.com/in/misbaharefin
"GaryDean" wrote:
When I use transactions with sql server I usually do this...
using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .

and this all works great. But now, I need to stretch the transaction across
to sql databases using two different connections i.e.

using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .
{
work
work
}//dispose of connection

using (SqlConnection2, - new SqlConnection . . . . .
{
work
work
}//dispose of connection
scope.Complete();
}//dispose of transaction scope

Is this supposed to work this way? Can a TransactionScope stretch across
many databases and cause a rollback of them all if an exception occurs?

--
Regards,
Gary Blakely
Jun 27 '08 #2
Hi Gary,

Sure, multiple connections are supported to be joined in the same
TransactionScope. And this is exactly the powerful feature of the new
System.Transactions namespace which help implicitly use MSDTC to perform
distributed transaction. (single connection based transaction can be done
via the ADO.NET 1.1 style ). Here are some articles that also mentioned
this:

#ADO.NET and System.Transactions
http://msdn2.microsoft.com/en-us/mag...163847.aspx#S4

#Revisiting System.Transactions
http://msdn2.microsoft.com/en-us/magazine/cc163527.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
Delighting our customers is our #1 priority. We welcome your comments and
suggestions about how we can improve the support we provide to you. Please
feel free to let my manager know what you think of the level of service
provided. You can send feedback directly to my manager at:
ms****@microsoft.com.

==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
>From: "GaryDean" <gd**********@newsgroup.nospam>
Subject: using Transactionscope with 2 dbs
Date: Wed, 16 Apr 2008 17:10:24 -0700
>
When I use transactions with sql server I usually do this...
using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .

and this all works great. But now, I need to stretch the transaction
across
>to sql databases using two different connections i.e.

using (TransactionScope scope = new TransactionScope)
{
using (SqlConnection1 = new SqlConnection . . . . .
{
work
work
}//dispose of connection

using (SqlConnection2, - new SqlConnection . . . . .
{
work
work
}//dispose of connection
scope.Complete();
}//dispose of transaction scope

Is this supposed to work this way? Can a TransactionScope stretch across
many databases and cause a rollback of them all if an exception occurs?

--
Regards,
Gary Blakely
Jun 27 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Rick_Kierner | last post by:
I am attempting to use the TransactionScope class to manage my transactions. I am running into an issue. My web server is in an NT work group. My SQL Server is in a domain. When my code...
3
by: Jason Huang | last post by:
Hi, MyForm is a C# Windows Form. MyFom has 3 GroupBoxes. Now I wanna update data from the textboxes in those 3 GroupBoxes. I have function Update1 for GroupBox1 to update table Table1, Update2...
3
by: OUSoonerTaz | last post by:
We are randomly getting this error message on our development and staging machines: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.; at...
2
by: Spottswoode | last post by:
Hi I have developed a client/server application in C# that worked perfectly in my office but not so perfectly after deploying it to our client. A little information about the architecture first:...
4
by: hardieca | last post by:
Hi, I'd really like to use TransactionScope within the Business Layer of my web application. A book I'm reading makes a note that it should not be used in a shared web hosting environment...
3
by: BLUE | last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL? Thanks, Luigi.
0
by: =?Utf-8?B?Sm9l?= | last post by:
Very weird; I lost a day worth of work because of this problem. I have an ASP.NET application written in VB that is using MySQL database. Shortly, a page creates a Customer record in the database...
0
by: RP | last post by:
I have a two classes, first named "ModCon" has procedures written for connections and the second named "ModRes" contains functions and procedures that can be reused. For my question it is important...
3
by: Aleksey Timonin | last post by:
Hi guys, I tried to use TransactionScope on to defferent TableAdapters like this: using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required)) {...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.