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

About TransactionScope

Hi to all folks,

i am trying to understand the use of System.Transactions in general and
TransactionScope particularly.

What am i allowed to do in a using statement that wraps a TransactionScope
object,
so this to be rollback in case of an exception or when i do not call
scope.complete ??
I mean, can i set an object's variables and then un-done these sets
automatically
when transaction rolls back ??

For example, the following code does not work, x.var remains 2 after the
suing statement,
even if i throw an exception after var set:

class Program
{
static void Main(string[] args)
{
X x = new X();
x.var = 1;
using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{
x.var = 2;
//scope.Complete();
}
Console.WriteLine(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??

Kikapu
Sep 20 '06 #1
3 7691
kikapu,

The TransactionScope class will only work on resources that register
themselves with the transaction mananger. Right now, the most immediate
example of a resource like this is a database. It doesn't automatically
just detect changes to anything in the scope and then roll them back if
Complete is not called.

However, it is possible to have local variables which are rolled back in
the event of an abort of a transaction. Check out the article by Juval Lowy
titled "Volatile Resource Managers in .NET Bring Transactions to the Common
Type", as it provides a mechanism by which to do this:

http://msdn.microsoft.com/msdnmag/is.../Transactions/

Of course, you shouldn't do this for ALL of your variables (that will be
a huge performance hit), but for the ones that you need rolled back in the
case of an abort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kikapu" <me******@newsgroups.nospamwrote in message
news:ew*************@TK2MSFTNGP03.phx.gbl...
Hi to all folks,

i am trying to understand the use of System.Transactions in general and
TransactionScope particularly.

What am i allowed to do in a using statement that wraps a TransactionScope
object,
so this to be rollback in case of an exception or when i do not call
scope.complete ??
I mean, can i set an object's variables and then un-done these sets
automatically
when transaction rolls back ??

For example, the following code does not work, x.var remains 2 after the
suing statement,
even if i throw an exception after var set:

class Program
{
static void Main(string[] args)
{
X x = new X();
x.var = 1;
using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress))
{
x.var = 2;
//scope.Complete();
}
Console.WriteLine(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??

Kikapu

Sep 20 '06 #2
Nicholas,

thanks for the reply!

i print now and will read this article that you send me.
Can you please give me a direction on how i can (a simple example)
register a resource with a transaction manager ??

Thanks again!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:O$**************@TK2MSFTNGP03.phx.gbl...
kikapu,

The TransactionScope class will only work on resources that register
themselves with the transaction mananger. Right now, the most immediate
example of a resource like this is a database. It doesn't automatically
just detect changes to anything in the scope and then roll them back if
Complete is not called.

However, it is possible to have local variables which are rolled back
in the event of an abort of a transaction. Check out the article by Juval
Lowy titled "Volatile Resource Managers in .NET Bring Transactions to the
Common Type", as it provides a mechanism by which to do this:

http://msdn.microsoft.com/msdnmag/is.../Transactions/

Of course, you shouldn't do this for ALL of your variables (that will
be a huge performance hit), but for the ones that you need rolled back in
the case of an abort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kikapu" <me******@newsgroups.nospamwrote in message
news:ew*************@TK2MSFTNGP03.phx.gbl...
>Hi to all folks,

i am trying to understand the use of System.Transactions in general and
TransactionScope particularly.

What am i allowed to do in a using statement that wraps a
TransactionScope object,
so this to be rollback in case of an exception or when i do not call
scope.complete ??
I mean, can i set an object's variables and then un-done these sets
automatically
when transaction rolls back ??

For example, the following code does not work, x.var remains 2 after the
suing statement,
even if i throw an exception after var set:

class Program
{
static void Main(string[] args)
{
X x = new X();
x.var = 1;
using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress) )
{
x.var = 2;
//scope.Complete();
}
Console.WriteLine(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??

Kikapu


Sep 20 '06 #3
kikapu,

The source code that comes with the article is a pretty good example in
itself.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kikapu" <me******@newsgroups.nospamwrote in message
news:eF****************@TK2MSFTNGP02.phx.gbl...
Nicholas,

thanks for the reply!

i print now and will read this article that you send me.
Can you please give me a direction on how i can (a simple example)
register a resource with a transaction manager ??

Thanks again!
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote
in message news:O$**************@TK2MSFTNGP03.phx.gbl...
>kikapu,

The TransactionScope class will only work on resources that register
themselves with the transaction mananger. Right now, the most immediate
example of a resource like this is a database. It doesn't automatically
just detect changes to anything in the scope and then roll them back if
Complete is not called.

However, it is possible to have local variables which are rolled back
in the event of an abort of a transaction. Check out the article by
Juval Lowy titled "Volatile Resource Managers in .NET Bring Transactions
to the Common Type", as it provides a mechanism by which to do this:

http://msdn.microsoft.com/msdnmag/is.../Transactions/

Of course, you shouldn't do this for ALL of your variables (that will
be a huge performance hit), but for the ones that you need rolled back in
the case of an abort.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"kikapu" <me******@newsgroups.nospamwrote in message
news:ew*************@TK2MSFTNGP03.phx.gbl...
>>Hi to all folks,

i am trying to understand the use of System.Transactions in general and
TransactionScope particularly.

What am i allowed to do in a using statement that wraps a
TransactionScope object,
so this to be rollback in case of an exception or when i do not call
scope.complete ??
I mean, can i set an object's variables and then un-done these sets
automatically
when transaction rolls back ??

For example, the following code does not work, x.var remains 2 after the
suing statement,
even if i throw an exception after var set:

class Program
{
static void Main(string[] args)
{
X x = new X();
x.var = 1;
using (TransactionScope scope = new
TransactionScope(TransactionScopeOption.Suppress ))
{
x.var = 2;
//scope.Complete();
}
Console.WriteLine(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??

Kikapu



Sep 20 '06 #4

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

Similar topics

4
by: Rick_Kierner | last post by:
I am attempting to use the TransactionScope class to manage my transactions. I am running into an issue. My web server is in an NT work group. My SQL Server is in a domain. When my code...
0
by: ste | last post by:
Please bear with this post.. its abit long winded.. but i thought it was important to describe what i am trying to achieve before i ask the questions (at the bottom) Thanks.....in advance ...
3
by: OUSoonerTaz | last post by:
We are randomly getting this error message on our development and staging machines: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.; at...
6
by: Mukesh | last post by:
Hi, I am new to 2.0 framework. I am trying to use TransactionScope in the following code. I took four lables. Started TransactionScope scope. After setting values to three labels I throw an...
6
by: Water Cooler v2 | last post by:
I heard from someone that we must not implement IDisposable for all classes. Can someone please tell me: 1. the reason why we must not implement IDisposable for all the classes we write. 2....
4
by: hardieca | last post by:
Hi, I'd really like to use TransactionScope within the Business Layer of my web application. A book I'm reading makes a note that it should not be used in a shared web hosting environment...
0
by: RP | last post by:
I have a two classes, first named "ModCon" has procedures written for connections and the second named "ModRes" contains functions and procedures that can be reused. For my question it is important...
3
by: Aleksey Timonin | last post by:
Hi guys, I tried to use TransactionScope on to defferent TableAdapters like this: using (TransactionScope transScope = new TransactionScope(TransactionScopeOption.Required)) {...
2
by: GaryDean | last post by:
When I use transactions with sql server I usually do this... using (TransactionScope scope = new TransactionScope) { using (SqlConnection1 = new SqlConnection . . . . . and this all works...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.