473,750 Members | 2,202 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TransactionScop e using

Hi guys,
I tried to use TransactionScop e on to defferent TableAdapters like this:

using (TransactionSco pe transScope = new
TransactionScop e(TransactionSc opeOption.Requi red))
{
TableAdapter1.I nsertQuery(id, name);
TableAdapter2.I nsertQuery(id, customerName, customerAddress );
transScope.Comp lete();
}

It was failed because each table adapter using it's own connection and
TransactionScop e doesn't manage with it...
So I modified my code:

using (TransactionSco pe transScope = new
TransactionScop e(TransactionSc opeOption.Requi red))
{
SqlConnection conn = TableAdapter1.C onnection;

conn.Open();
TableAdapter1.I nsertQuery(id, name);
TableAdapter2.C onnection = conn;
TableAdapter2.I nsertQuery(id, customerName, customerAddress );
conn.Close();
transScope.Comp lete();
}
Am I using TransactionScop e correct? And if you see any problem in my code,
let me know.
Thanks a lot
Aleksey

Jan 15 '08 #1
3 8026
Aleskey,

What is the exception you are getting when you don't share the
connection? The connection ^should^ pick up on the ambient transaction and
enlist in it.

Then again, the provider might not even support it, but most providers
(from .NET 2.0 on, that is) should support it.

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

"Aleksey Timonin" <al******@mdgme dical.comwrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
Hi guys,
I tried to use TransactionScop e on to defferent TableAdapters like this:

using (TransactionSco pe transScope = new
TransactionScop e(TransactionSc opeOption.Requi red))
{
TableAdapter1.I nsertQuery(id, name);
TableAdapter2.I nsertQuery(id, customerName, customerAddress );
transScope.Comp lete();
}

It was failed because each table adapter using it's own connection and
TransactionScop e doesn't manage with it...
So I modified my code:

using (TransactionSco pe transScope = new
TransactionScop e(TransactionSc opeOption.Requi red))
{
SqlConnection conn = TableAdapter1.C onnection;

conn.Open();
TableAdapter1.I nsertQuery(id, name);
TableAdapter2.C onnection = conn;
TableAdapter2.I nsertQuery(id, customerName, customerAddress );
conn.Close();
transScope.Comp lete();
}
Am I using TransactionScop e correct? And if you see any problem in my
code, let me know.
Thanks a lot
Aleksey

Jan 15 '08 #2
The exception is:
Network access for Distributed Transaction Manager (MSDTC) has been
disabled.....
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote in
message news:ub******** ******@TK2MSFTN GP03.phx.gbl...
Aleskey,

What is the exception you are getting when you don't share the
connection? The connection ^should^ pick up on the ambient transaction
and enlist in it.

Then again, the provider might not even support it, but most providers
(from .NET 2.0 on, that is) should support it.

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

"Aleksey Timonin" <al******@mdgme dical.comwrote in message
news:e2******** ******@TK2MSFTN GP05.phx.gbl...
>Hi guys,
I tried to use TransactionScop e on to defferent TableAdapters like this:

using (TransactionSco pe transScope = new
TransactionSco pe(TransactionS copeOption.Requ ired))
{
TableAdapter1. InsertQuery(id, name);
TableAdapter2. InsertQuery(id, customerName, customerAddress );
transScope.Com plete();
}

It was failed because each table adapter using it's own connection and
TransactionSco pe doesn't manage with it...
So I modified my code:

using (TransactionSco pe transScope = new
TransactionSco pe(TransactionS copeOption.Requ ired))
{
SqlConnectio n conn = TableAdapter1.C onnection;

conn.Open();
TableAdapter1. InsertQuery(id, name);
TableAdapter2. Connection = conn;
TableAdapter2. InsertQuery(id, customerName, customerAddress );
conn.Close() ;
transScope.Com plete();
}
Am I using TransactionScop e correct? And if you see any problem in my
code, let me know.
Thanks a lot
Aleksey


Jan 15 '08 #3
Aleskey,

Have you configured DTC to allow distributed transactions across the
network? You need to go to Component Services (in the Administrative Tools
section) and then select the properties for your computer. You can then
configure the DTC on the MSDTC tab.

You also have to make sure that this is enabled on the other machine as
well, as it is participating in a distributed transaction.

Your code will allow you to get around the fact that it is a distributed
transaction by maintaining one connection, however, if you decide to compose
actions across different calls and want them to be included in the same
transaction, you would have to make your connection available to all of
those calls (which is a really bad idea). That's why it's a better idea to
enable the distributed transaction.

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

"Aleksey Timonin" <al******@mdgme dical.comwrote in message
news:%2******** ********@TK2MSF TNGP06.phx.gbl. ..
The exception is:
Network access for Distributed Transaction Manager (MSDTC) has been
disabled.....
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard .caspershouse.c omwrote
in message news:ub******** ******@TK2MSFTN GP03.phx.gbl...
>Aleskey,

What is the exception you are getting when you don't share the
connection? The connection ^should^ pick up on the ambient transaction
and enlist in it.

Then again, the provider might not even support it, but most providers
(from .NET 2.0 on, that is) should support it.

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

"Aleksey Timonin" <al******@mdgme dical.comwrote in message
news:e2******* *******@TK2MSFT NGP05.phx.gbl.. .
>>Hi guys,
I tried to use TransactionScop e on to defferent TableAdapters like this:

using (TransactionSco pe transScope = new
TransactionSc ope(Transaction ScopeOption.Req uired))
{
TableAdapter1 .InsertQuery(id , name);
TableAdapter2 .InsertQuery(id , customerName, customerAddress );
transScope.Co mplete();
}

It was failed because each table adapter using it's own connection and
TransactionSc ope doesn't manage with it...
So I modified my code:

using (TransactionSco pe transScope = new
TransactionSc ope(Transaction ScopeOption.Req uired))
{
SqlConnecti on conn = TableAdapter1.C onnection;

conn.Open() ;
TableAdapter1 .InsertQuery(id , name);
TableAdapter2 .Connection = conn;
TableAdapter2 .InsertQuery(id , customerName, customerAddress );
conn.Close( );
transScope.Co mplete();
}
Am I using TransactionScop e correct? And if you see any problem in my
code, let me know.
Thanks a lot
Aleksey



Jan 15 '08 #4

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

Similar topics

0
1959
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..................
3
7120
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)
6
1773
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";
3
7721
by: kikapu | last post by:
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
4
5555
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
5
8639
by: RP | last post by:
I tried following code but it generates error at line (using .....): Error 23 The type or namespace name 'TransactionScope' could not be found (are you missing a using directive or an assembly reference?) =========================================== private void cmdProceed_Click(object sender, EventArgs e) {
0
1439
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();
3
2896
by: Michael Schöller | last post by:
Hello, First of all english is not my natural language so please fogive me some bad mistakes in gramatic and use of some vocables :). I have a great problem here. Well I will not use it anymore but I want to know why it is as it is ^^. I tried with .NET3.0 but I think it will be the same with 2.0 and 3.5. MSDTC is configured and working.
2
2635
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) {
0
8999
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
8836
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
9575
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...
1
9338
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,...
0
8260
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...
1
6803
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4712
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
3322
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
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.