473,385 Members | 1,907 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,385 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 3872
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: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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...

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.