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

Transaction scope question

I'm using TransactionScope as follows...

using TransactionScope myScope = new TransactionScope())
{
using (SqlConnection conn = new SqlConnection())
{
conn.ConnectionString = GlobalData.connString;
conn.Open();
...................code that does db work
myScope.Complete();
}//dispose of connection
}//dispose of myScope

The code calls down the call chain where all of the database work gets done.
and all of this, so far, works just fine.

However, I put some code in the Application_Error event in Global.asax to
log exception data to a SQL Server Database table. The code works but it's
getting rolled back when the unhandled exception occurs within the scope.

Is there any way I can keep these updates in the Application_Error event
from getting rolled back?

--
Regards,
Gary Blakely
Apr 26 '07 #1
3 2029
Hi Gary,

From your description, you're using the .net 2.0 System.Transactions
component to provide transaction control over the data access code in your
ASP.NET 2.0 application. However, you found that if there occurs exception
within the TransactionScope you created, the data base writing code(write
log) in Application_Error event will also be rollback, you're wondering how
to prevent this, correct?

According to your scenario, I have performed some test on my side and here
is my test result:

When you put data accessing code in Application_Start event, have you also
create a TransactionScope around the logging code? If you create one with
default constructor, it will make the wrapped data access code join the
existing Transaction (from your page's started Transaction scope). I think
that should be why your logging code in Application_Start event always be
rollback (together with the data access code in page which throw exception).

To prevent the data access code in your Application_Start event from being
affected by another transaction in the calling context, you can explicitly
wrapper it with a new TransactionScope and set its TransactionScopeOption
as "Suppressed" ,thus, the wrappered code won't join any exidting
transaction. e.g.

==================
void Application_Error(object sender, EventArgs e)
{

using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{

//do logging here

}

}

}
==============================

here is a good msdn article that has provide detailed description of the
..net 2.0 Transaction support:

#Introducing System.Transactions in the .NET Framework 2.0
http://msdn2.microsoft.com/en-us/library/ms973865.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

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.

Apr 27 '07 #2
Steven,
Thanks. That sounds like what I'm after.

--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:lz**************@TK2MSFTNGHUB02.phx.gbl...
Hi Gary,

From your description, you're using the .net 2.0 System.Transactions
component to provide transaction control over the data access code in your
ASP.NET 2.0 application. However, you found that if there occurs exception
within the TransactionScope you created, the data base writing code(write
log) in Application_Error event will also be rollback, you're wondering
how
to prevent this, correct?

According to your scenario, I have performed some test on my side and here
is my test result:

When you put data accessing code in Application_Start event, have you also
create a TransactionScope around the logging code? If you create one with
default constructor, it will make the wrapped data access code join the
existing Transaction (from your page's started Transaction scope). I think
that should be why your logging code in Application_Start event always be
rollback (together with the data access code in page which throw
exception).

To prevent the data access code in your Application_Start event from being
affected by another transaction in the calling context, you can explicitly
wrapper it with a new TransactionScope and set its TransactionScopeOption
as "Suppressed" ,thus, the wrappered code won't join any exidting
transaction. e.g.

==================
void Application_Error(object sender, EventArgs e)
{

using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{

//do logging here

}

}

}
==============================

here is a good msdn article that has provide detailed description of the
net 2.0 Transaction support:

#Introducing System.Transactions in the .NET Framework 2.0
http://msdn2.microsoft.com/en-us/library/ms973865.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

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.



Apr 28 '07 #3
Steven,
thanks. That worked great.

--
Regards,
Gary Blakely
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:lz**************@TK2MSFTNGHUB02.phx.gbl...
Hi Gary,

From your description, you're using the .net 2.0 System.Transactions
component to provide transaction control over the data access code in your
ASP.NET 2.0 application. However, you found that if there occurs exception
within the TransactionScope you created, the data base writing code(write
log) in Application_Error event will also be rollback, you're wondering
how
to prevent this, correct?

According to your scenario, I have performed some test on my side and here
is my test result:

When you put data accessing code in Application_Start event, have you also
create a TransactionScope around the logging code? If you create one with
default constructor, it will make the wrapped data access code join the
existing Transaction (from your page's started Transaction scope). I think
that should be why your logging code in Application_Start event always be
rollback (together with the data access code in page which throw
exception).

To prevent the data access code in your Application_Start event from being
affected by another transaction in the calling context, you can explicitly
wrapper it with a new TransactionScope and set its TransactionScopeOption
as "Suppressed" ,thus, the wrappered code won't join any exidting
transaction. e.g.

==================
void Application_Error(object sender, EventArgs e)
{

using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{

//do logging here

}

}

}
==============================

here is a good msdn article that has provide detailed description of the
net 2.0 Transaction support:

#Introducing System.Transactions in the .NET Framework 2.0
http://msdn2.microsoft.com/en-us/library/ms973865.aspx

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

==================================================

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.



Apr 29 '07 #4

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

Similar topics

5
by: Klemens | last post by:
I get SQL30090 reason 18 by trying to do an insert in a federated table and an update in a local table in one transaction Do I have to change some settings to get done or ist this not possible by...
2
by: Banski | last post by:
Hi, Im trying to use SELECT @@IDENTITY in a transaction. But it always returns 0. Im using an ms access database. And using the following code. What am i doing wrong? Best regards banski ...
3
by: rdemyan via AccessMonster.com | last post by:
I have some unbound forms that I want to use transaction wrappers on when updating the table. My question is on the scope of what transaction processing will do. I'm going to keep it simple with...
4
by: liming | last post by:
Hi, I know it's possible to have transactions with Typed DataSet, but I have yet to find an example of it. For example, I have two typed TableAdapter CommerceDataSet.xsd ...
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...
5
by: Allan Ebdrup | last post by:
I'm using dotNet 2.0 and System.Transactions to run transactions that span multiple database queries, Now I would like to log any Sql errors that occur in the transaction, but when I insert the...
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...
2
by: John Dow | last post by:
I am new to WCF, so please point me to the right direction. I created 2 WCF serivces, each one uses a difference database connection in the back end. Now from the client application, I need to...
6
by: BobRoyAce | last post by:
Let's say that I am performing a bunch of insert/update queries within a transaction that is created as follows: Dim cnn As New SqlClient.SqlConnection(My.Settings.GRPConnectionString)...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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?
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
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.