473,748 Members | 5,230 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When in transaction scope how do I run a query outside transaction?

I'm using dotNet 2.0 and System.Transact ions 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 logentry into the database the
query that does the inserting is automatically enlisted in the running
transaction and rolled back when the transaction aborts.
How do I run the query inserting into the log outside the current
transaction, so that it is not rolled back with the current transaction?
I'm guessing I create a new transaction scope that doesn't enlist in the
current transaction, is this correct? And if so, how do I do it?

Kind Regards,
Allan Ebdrup
Apr 4 '07 #1
5 7402
does this work?

using(Transacti onScope ts = new
TransactionScop e(TransactionSc opeOption.Suppr ess)) {
// your work
ts.Complete();
}

Marc
Apr 4 '07 #2
While supporess will work, it's probably not the best idea in this
situation, especially if the logging requires more than one operation and
the whole thing has to be atomic.

It's probably better to create a new transaction scope with RequiresNew
instead.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marc Gravell" <ma**********@g mail.comwrote in message
news:Or******** ******@TK2MSFTN GP05.phx.gbl...
does this work?

using(Transacti onScope ts = new
TransactionScop e(TransactionSc opeOption.Suppr ess)) {
// your work
ts.Complete();
}

Marc

Apr 4 '07 #3
I considered that, but guessed (albeit without any evidence) that
typical logging would be doing a very simple single insert (hence no
huge atomicity requirement) without querying any data first (so no
isolation-leevl range-lock subtleties) nor lock escalation, so *for
this specific scenario* suppress might be OK.

Of course, another approach is to use a queue for logging, cleared
down on a (not too irregular) basis, so that a: the main transactional
code isn't impeded by logging IO, and b: when loggin *does* happen it
can happen in a batch (or even SqlBulkCopy depending on throughput)
rather than individual statements.

Marc

Apr 4 '07 #4
Marc,

Your assumption falls short, because there might be more than one
operation being performed that is not a read.

For example, you might have a general audit/log table with the time the
audit took place, etc, etc, and then specific detail tables related to the
general table.

What it comes down to is that unless it is a single operation with a
single resource, you most definitely want a new transaction. Even with file
systems that are becoming transactional (NTFS in Vista), it's more important
than ever to take this into account.

I agree that a queue operation might be a good choice here, but even
then, depending on the type of queue, you still have to take transactions
into account.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard. caspershouse.co m

"Marc Gravell" <ma**********@g mail.comwrote in message
news:11******** **************@ n59g2000hsh.goo glegroups.com.. .
>I considered that, but guessed (albeit without any evidence) that
typical logging would be doing a very simple single insert (hence no
huge atomicity requirement) without querying any data first (so no
isolation-leevl range-lock subtleties) nor lock escalation, so *for
this specific scenario* suppress might be OK.

Of course, another approach is to use a queue for logging, cleared
down on a (not too irregular) basis, so that a: the main transactional
code isn't impeded by logging IO, and b: when loggin *does* happen it
can happen in a batch (or even SqlBulkCopy depending on throughput)
rather than individual statements.

Marc

Apr 5 '07 #5
I will be dooing several operations on the database in the logging, so I
quess I should use RequiresNew.
Thanks for all the feedback.

Kind Regards,
Allan Ebdrup
Apr 10 '07 #6

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

Similar topics

1
18487
by: Steve Thorpe | last post by:
Hi have have two linked SQL Servers and I am trying to get things working smootly/quickly. Should I be using 'BEGIN TRANSACTION' or 'BEGIN DISTRIBUTED TRANSACTION' ? Basicly, these SPs update a local table and a remote table in the same transaction. I cant have one table updated and not the other. Please dont say replicate the tables either as at this time, this is is not an option. I have for example a number of stored procedures...
1
4025
by: Rhy Mednick | last post by:
I'm creating a custom control (inherited from UserControl) that is displayed by other controls on the form. I would like for the control to disappear when the user clicks outside my control the same way a menu does. To do this my control needs to get notified when the user tried to click off of it. The Leave and LostFocus events of the UserControl work most of the time but not always. For example, if they click on a part of the form...
3
27513
by: Ollie Riches | last post by:
"Distributed transaction completed. Either enlist this session in a new transaction or the NULL transaction." I am recieving the above error when attempt to access a remote sql server database 2000 (sp3a) from ADO.Net. The database is on a windows 2003 machine and the ado.net code (web services) are on another winsdows 2003 machine in the same domain. I have configure the DTC to allow transactions and followed the resolution in the...
2
2044
by: Pascal Polleunus | last post by:
(another try with a different subject as it doesn't seem to work with "EXECUTE + transaction = unexpected error -8" :-/) Hi, It seems that there is a problem when executing a dynamic commands containing a transaction... Here's a simple example...
3
1935
by: sphinney | last post by:
I have a form with a subform. The code of the parent form alters the "Recordsource" property of a subform. Altering this property automatically triggers the subform to requery a table that has lots of records (so it takes a few seconds). I need to know when the subform query is finished before allowing the code in my parent form to continue. Is there an event that captures when a form query is finished? Under a different posting a couple...
3
2043
by: GaryDean | last post by:
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();
2
1748
by: cmrhema | last post by:
Hello I am trying to run a program to check for transaction scope I have written the following code. But it seems I need to add a namespace or reference What namespace am I supposed to add thanks using (TransactionScope scope = new TransactionScope(TransactionScope.Required, options))
0
1547
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 and if successful, creates a directory on the web server. I was using Transaction Scope to accomplish this action; here is the code excerpt: ' Initialize the return value to zero Dim returnValue As Integer = 0
1
1186
by: Randa | last post by:
I'm Using Transaction Scope to implement a transaction against SQL Server 2000. Locally its working Perfectly and no problem happens; but when trying to do the same action on a remote server it dosn't work; it gives no errors or exception just doesn't rollback when an exception appears before Completion. The server's DTC Service is working, and no firewall is installed at the SQl Server machine Does anyone know what may be the reason for...
0
8991
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8830
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9544
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9247
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8243
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4874
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3313
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2215
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.