473,397 Members | 2,056 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,397 software developers and data experts.

Detect if Distributed Transaction is used or just SQL 2005 internal transaction?

Hi,

I have few questions related to .NET 2.0 TransactionScope class behavior:

1. Check Transaction.Current.TransactionInformation.Distrib utedIdentifier to
identify if distributed transaction is used - is it accurate way?

2. I have the following code blocks -

In code block 1, the first check the DistributedIdentifier is ALL 0s so it
tells me the distributed transaction is not used yet but right after the
second call to SqlHelper.ExecuteNonQuery(connectionString) it looks like the
distributed transaction is started - the connection string is exactly same
and access SQL 2005 database - it should only use SQL 2005 internal
transaction according to document

In code block 2 is almost identical to the block1 except I specifically open
the Sqlconnection and then pass the connection object instead of the
connection string to SqlHelper.ExecuteNonQuery(SqlConnection) AND this works
fine and NO distributed transaction is started.

It's OK in beta2 but I would think .NET runtime should be able to understand
only SQL 2005 database is involved even using connectionString instead of
passing SqlConnection around. Any thoughts?

ALSO, the TransactionScope's default isolationLevel is Serializable - which
I think it should be set to ReadCommitted

Block 1:
using (TransactionScope ts = new
TransactionScope(TransactionScopeOption.Required))
{
string SQL = "INSERT INTO test(name) values('John')";
SqlHelper.ExecuteNonQuery(this.m_connectionString, CommandType.Text,
SQL);

string msg = "";
if (Transaction.Current != null)
{
TransactionInformation ti = Transaction.Current.TransactionInformation;
msg = String.Format("LocalID = {0} Status = {1} Distributed ID = {2}
Isolation = {3}", ti.LocalIdentifier, ti.Status.ToString(),
(ti.DistributedIdentifier == null ? "" :
ti.DistributedIdentifier.ToString()),
Transaction.Current.IsolationLevel.ToString());
}
else
{
msg = "No Transaction Context";
}
MessageBox.Show(msg);

SQL = "INSERT INTO test(name) values('Jack')";
SqlHelper.ExecuteNonQuery(this.m_connectionString, CommandType.Text,
SQL);
if (Transaction.Current != null)
{
TransactionInformation ti = Transaction.Current.TransactionInformation;
msg = String.Format("LocalID = {0} Status = {1} Distributed ID = {2}
Isolation = {3}", ti.LocalIdentifier, ti.Status.ToString(),
(ti.DistributedIdentifier == null ? "" :
ti.DistributedIdentifier.ToString()),
Transaction.Current.IsolationLevel.ToString());
}
else
{
msg = "No Transaction Context";
}
MessageBox.Show(msg);

ts.Complete();
}

Block2:
using (TransactionScope ts = new
TransactionScope(TransactionScopeOption.Required))
{
using (SqlConnection conn = new SqlConnection(m_connectionString))
{
conn.Open();

string SQL = "INSERT INTO test(name) values('John')";
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL);

string msg = "";
if (Transaction.Current != null)
{
TransactionInformation ti =
Transaction.Current.TransactionInformation;
msg = String.Format("LocalID = {0} Status = {1} Distributed ID = {2}
Isolation = {3}", ti.LocalIdentifier, ti.Status.ToString(),
(ti.DistributedIdentifier == null ? "" :
ti.DistributedIdentifier.ToString()),
Transaction.Current.IsolationLevel.ToString());
}
else
{
msg = "No Transaction Context";
}
MessageBox.Show(msg);

SQL = "INSERT INTO test(name) values('Jack')";
SqlHelper.ExecuteNonQuery(conn, CommandType.Text, SQL);
if (Transaction.Current != null)
{
TransactionInformation ti =
Transaction.Current.TransactionInformation;
msg = String.Format("LocalID = {0} Status = {1} Distributed ID = {2}
Isolation = {3}", ti.LocalIdentifier, ti.Status.ToString(),
(ti.DistributedIdentifier == null ? "" :
ti.DistributedIdentifier.ToString()),
Transaction.Current.IsolationLevel.ToString());
}
else
{
msg = "No Transaction Context";
}
MessageBox.Show(msg);

ts.Complete();
}
Thanks very much!
John

Nov 17 '05 #1
2 3874
Hi John,

Welcome to .NET newsgroup.
As for new Trasaction supporting question you mentioned in .net 2.0, we'll
have a check in the latest beta version and update you as soon as we got
any info.
Thanks for your understanding.

Steven Cheng
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)





Nov 17 '05 #2
Hi John,

1. Yes, I think it's accurate. If the transaction is promoted to a
two-phase commit transaction, this property returns its unique identifier.
If the transaction is not promoted, the value is null.

2. When you pass a connection string to the SqlHelper.ExecuteNonQuery
method, it will create a new SqlConnection object automatically, which
makes the trasaction promoted. Since the final version of .NET framework
hasn't been released yet, we're not quite sure if the feature will change
in the future.

For ADO.NET 2.0 issues, you can also post in the following newsgroup. It is
dedicated to ADO.NET 2.0 issues. Thanks!

http://forums.microsoft.com/msdn/Sho...spx?ForumID=45

Kevin Yu
=======
"This posting is provided "AS IS" with no warranties, and confers no
rights."

Nov 17 '05 #3

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

Similar topics

7
by: Richard Maher | last post by:
Hi, I am seeking the help of volunteers to test some software that I've developed which facilitates distributed two-phase commit transactions, encompassing any resource manager (e.g. SQL/Server...
0
by: DotNetJunkies User | last post by:
I am writing a distributed transaction code. My current scenario include a client database(Suppose client- having 4 main database) which can be installed anywhere which would connect to a public...
1
by: Avanish Pandey | last post by:
Hello All We have 3 differen services (in 3 different server) Service A,B,C . We want to implement distributed transaction when call methods of B and C from A. Is it possible? if yes then how? ...
0
by: Manoj Sharma | last post by:
I am performance testing some batch processing engines. These are written in ..NET and SQL Server and are typically concerned with generating XML files out of data retrieved from the database. I...
0
by: CJM | last post by:
I'm executing a series of SQL Server stored procs in one ASP page. They are wrapped within an ADO transaction. The reason for several SP calls is that the SPs are used individually elsewhere in the...
2
by: Jo Siffert | last post by:
Hi all, I would like to perform an INSERT INTO LINKEDSVR.dbo.xyz.abc SELECT ... FROM dbo.dfg where LINKEDSVR is a linked server on another machine. Both servers are running SQLServer 2000...
8
by: Rob S | last post by:
I have UDB 8.1 Personal Edition installed. I'm using Development centre to develop JAVA Stored Procedues. I am unable to debug them. I have installed IBM Distributed Debugger and have set...
0
by: gshawn3 | last post by:
Hi, I am having a hard time creating a Trigger to update an Oracle database. I am using a SQL Server 2005 Express database on a Win XP Pro SP2 desktop, linked to an Oracle 10g database on a...
2
by: rbg | last post by:
Hi, On My local SQL server I have added a linked server to another SQL server (remoteserver) in another Windows NT Domain. When I run this code select count(*) from...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.