Hi to all folks,
i am trying to understand the use of System.Transact ions in general and
TransactionScop e particularly.
What am i allowed to do in a using statement that wraps a TransactionScop e
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 (TransactionSco pe scope = new
TransactionScop e(TransactionSc opeOption.Suppr ess))
{
x.var = 2;
//scope.Complete( );
}
Console.WriteLi ne(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??
Kikapu 3 7721
kikapu,
The TransactionScop e 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.co m
"kikapu" <me******@newsg roups.nospamwro te in message
news:ew******** *****@TK2MSFTNG P03.phx.gbl...
Hi to all folks,
i am trying to understand the use of System.Transact ions in general and
TransactionScop e particularly.
What am i allowed to do in a using statement that wraps a TransactionScop e
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 (TransactionSco pe scope = new
TransactionScop e(TransactionSc opeOption.Suppr ess))
{
x.var = 2;
//scope.Complete( );
}
Console.WriteLi ne(x.var);
}
}
class X
{
public int var;
}
}
I am sure that i am missing something here, can anyone help ??
Kikapu
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.c omwrote in
message news:O$******** ******@TK2MSFTN GP03.phx.gbl...
kikapu,
The TransactionScop e 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.co m
"kikapu" <me******@newsg roups.nospamwro te in message
news:ew******** *****@TK2MSFTNG P03.phx.gbl...
>Hi to all folks,
i am trying to understand the use of System.Transact ions in general and TransactionSco pe particularly.
What am i allowed to do in a using statement that wraps a TransactionSco pe object, so this to be rollback in case of an exception or when i do not call scope.comple te ?? I mean, can i set an object's variables and then un-done these sets automaticall y 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 (TransactionSco pe scope = new TransactionSco pe(TransactionS copeOption.Supp ress)) { x.var = 2; //scope.Complete( ); } Console.WriteLi ne(x.var); } } class X { public int var; } }
I am sure that i am missing something here, can anyone help ??
Kikapu
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.co m
"kikapu" <me******@newsg roups.nospamwro te in message
news:eF******** ********@TK2MSF TNGP02.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.c omwrote
in message news:O$******** ******@TK2MSFTN GP03.phx.gbl...
>kikapu,
The TransactionScop e 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.co m
"kikapu" <me******@newsg roups.nospamwro te in message news:ew******* ******@TK2MSFTN GP03.phx.gbl...
>>Hi to all folks,
i am trying to understand the use of System.Transact ions in general and TransactionSc ope particularly.
What am i allowed to do in a using statement that wraps a TransactionSc ope object, so this to be rollback in case of an exception or when i do not call scope.complet e ?? I mean, can i set an object's variables and then un-done these sets automatical ly 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 (TransactionSco pe scope = new TransactionSc ope(Transaction ScopeOption.Sup press)) { x.var = 2; //scope.Complete( ); } Console.WriteLi ne(x.var); } } class X { public int var; } }
I am sure that i am missing something here, can anyone help ??
Kikapu This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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 attempts to execute the
Complete method of the TransactionScope object, I get the following error:
"The transaction has already been implicitly or explicitly committed or
aborted"
I have tried altering the registry entry to...
|
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
Steve
Okay.. here goes..................
|
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
System.Data.Common.UnsafeNativeMethods.OraMTSJoinTxn(OciEnlistContext
pCtxt, IDtcTransaction pTrans)
at
System.Data.OracleClient.TracedNativeMethods.OraMTSJoinTxn(OciEnlistContext
pCtxt, IDtcTransaction pTrans)
|
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 exception. I expexted
all label value would remain as method Complete() of TransactionScope
scope was not complete. But actually three labels are showing new
values.
label1.Text="1";
|
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. what is the correct way of implementing IDisposable.Dispose?
3. what is the preferred way, if there is one over the other, of
calling the Dispose method on an object that implements IDisposable. Is
it the way that uses the "using(object){}" construct...
| |
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 because the server may get
re-configured. Can anyone elaborate on this?
Regards,
Chris
|
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 to add
sample codes of the two classes and later the code from a Form's
button click event which is giving problem.
========================================
public string ConString;
public SqlConnection myCN = new SqlConnection();
|
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))
{
TableAdapter1.InsertQuery(id, name);
TableAdapter2.InsertQuery(id, customerName, customerAddress);
transScope.Complete();
}
|
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 great. But now, I need to stretch the transaction across
to sql databases using two different connections i.e.
using (TransactionScope scope = new TransactionScope)
{
|
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...
|
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,...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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
| |
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |