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

Transactions in dotNet 2.0

I have a transaction in dotNet 2.0:
-------------
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
options.Timeout = new TimeSpan(3, 0, 0); //maximum 3 hour transaction
using (TransactionScope transactionScope = new
TransactionScope(TransactionScopeOption.Required, options))
{
....
}
-------------
When it runs I have a sql query that fails some times, but I catch the
exception and correct the problem. When I continue I get the error
"the operation is not valid for the state of the transaction." so the
transaction has failed because the sql query failed.
How can I get the transaction to ignore the error and continue running?
Do I have to write code that never throws an SQL exception?

Kind Regards,
Allan Ebdrup
Jun 12 '07 #1
4 6907
Allan,

Pretty much. For SQL server, once you fail on a connection, the part of
the transaction related to SQL Server will never commit.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Allan Ebdrup" <eb****@noemail.noemailwrote in message
news:%2****************@TK2MSFTNGP05.phx.gbl...
>I have a transaction in dotNet 2.0:
-------------
TransactionOptions options = new TransactionOptions();
options.IsolationLevel = System.Transactions.IsolationLevel.Serializable;
options.Timeout = new TimeSpan(3, 0, 0); //maximum 3 hour transaction
using (TransactionScope transactionScope = new
TransactionScope(TransactionScopeOption.Required, options))
{
...
}
-------------
When it runs I have a sql query that fails some times, but I catch the
exception and correct the problem. When I continue I get the error
"the operation is not valid for the state of the transaction." so the
transaction has failed because the sql query failed.
How can I get the transaction to ignore the error and continue running?
Do I have to write code that never throws an SQL exception?

Kind Regards,
Allan Ebdrup
Jun 12 '07 #2
Hi Allan,

Yes, as Nicholas has mentioned, the problem here is that you try execution
further commands over a connection where an exception/failure has already
occur. When you using the TransactionScope to manage transaction, the .NET
transaction engine will help you automatically deal with the underlying
transaction on each connection(in the scope), whenever you failed on a
connection, you'll not be able to execute and commit command against that
connection. For your scenario, I suggest you consider create and open a
new connection after exception occurs and you handled it. Thus, the
sequential execution on the new created connection can also continue and
commit (within the same TransactionScope)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.
Jun 13 '07 #3
"Steven Cheng[MSFT]" <st*****@online.microsoft.comwrote in message
news:cR**************@TK2MSFTNGHUB02.phx.gbl...
<snip>
For your scenario, I suggest you consider create and open a
new connection after exception occurs and you handled it. Thus, the
sequential execution on the new created connection can also continue and
commit (within the same TransactionScope)
Thank you for the feedback, I've already changed the application so no SQL
exceptions should occur.
But your information is very valuable.

Kind Regards,
Allan Ebdrup
Jun 13 '07 #4
You're welcome :)

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead
This posting is provided "AS IS" with no warranties, and confers no rights.

Jun 14 '07 #5

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...
3
by: Irfan | last post by:
There are several ways of handling Transactions in DotNet. Some of them are 1. Using COM+ Serviced Component. 2. Using ADO .Net 3. using stored procedure What is the best way of handling...
11
by: Mike P | last post by:
I've been using C# transactions for a while and had no problems with them. Using try catch blocks I can trap basically all possible errors and rollback all necessary data. Over the last few...
2
by: Antuane | last post by:
any one have any idea how transactions could be enabled in webservices. i.e., suppose i've got 2 methods - one to add a contact, & the other to set some miscellaneous details for the contact, in a...
5
by: Allan Ebdrup | last post by:
I'm using dotNet 2.0 and VS2005, I would like to have some code call several webservices that I have written that insert data into a DB (MSSQL 2000) inside a transaction. So that I can rollback if...
12
by: Rami | last post by:
I have some requirement for an automated payment system. The system has four machines setup as follows: 1- Two machines have a clustered database. 2- Two machines have a .net business logic...
8
by: Allan Ebdrup | last post by:
I've implemented transactions in my dotNet 2.0 project using System.Transactions and TransactionScope. --- TransactionOptions options = new TransactionOptions(); options.IsolationLevel =...
3
by: Ken | last post by:
I used the classes (SqlCommand, SqlConnection) of part of System.Data namespace. I got an error which mentioned "Could not load file or assembly assembly 'System.Transactions, Version=2.0.0.0,...
3
by: psycho | last post by:
I am working on an N-tier application using following components: 1. Data Access Layer using DLINQ which consists of Data Context class and Table Mapping classes. 2. Business Logic Layer....
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: 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
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,...
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
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...
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.