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

Home Posts Topics Members FAQ

Error while using TransactionScop e

RP
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.

========[ ModCon Code ]=============== =============== ==
public string ConString;
public SqlConnection myCN = new SqlConnection() ;

public void OpenConnection( )
{
if (myCN.State == ConnectionState .Closed)
{
myCN.Connection String =
ReadConnectionS tringFromFile() ;
}
try
{
if (myCN.State != ConnectionState .Open)
{
myCN.Open();
}
}
catch (Exception ex)
{

}
}

public void CloseConnection ()
{
if (myCN.State == ConnectionState .Open)
try
{
myCN.Close();
}
catch (Exception ex)
{

}
}
=============== =============== =============== ======
=======[ ModRes Code ]=============== ==============
public Int32 InsertNewRecord (string myQuery)
{
objModCon.OpenC onnection();
SqlCommand cmdInsert = new SqlCommand(myQu ery,
objModCon.myCN) ;
try
{
Int32 RecordsAffected = cmdInsert.Execu teNonQuery();
return RecordsAffected ;
}
catch (Exception ex)
{
MessageBox.Show ("Routine: ModReUsable-
InsertNewRecord (" + myQuery + ") " + ex.ToString(), "Error:",
MessageBoxButto ns.OK, MessageBoxIcon. Error);
return 0;
}
finally
{
cmdInsert.Dispo se();
objModCon.Close Connection();
}
}
=============== =============== =============== ====

=========[ Windows Form Code Sample ]=============== ==
private void cmdProceed_Clic k(object sender, EventArgs e)
{
using (TransactionSco pe scope = new
TransactionScop e())
{
//Start Generation
GenerateALL();
scope.Complete( );
}
}
}

private void GenerateAll()
{
Loop Starts
Dim qInsert = ".............. .";
ModRes.InsertNe wRecord(qInsert );

//Call Function A
FunctionA();

Dim qInsert = ".............. .";
ModRes.InsertNe wRecord(qInsert );

FunctionB();
}

private void FunctionA()
{
Dim qUpdate = ".............. ."
ModRes.InsertNe wRecord(qUpdate );
}

private void FunctionB()
{
............... .
}
=============== =============== =============== =============== =======

The above code from Windows Form Button Click event works well if I
don't use TransactionScop e, whereas when I use TransactionScop e it
displays error in Function A:

======[ ERROR ]======
ModRes.InsertNe wRecord(....... .)
System.InvalidO perationExcepti on: ExecuteNonQuery requires an open and
available connection. The connection's current state is closed.
=============== ======

The exception is returned by Class ModRes, InsertNewRecord function.
Why? Does TransactionScop e not allowing calls and execution of SQL in
other classes.

Oct 12 '07 #1
0 1439

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

Similar topics

3
4204
by: Jason Huang | last post by:
Hi, MyForm is a C# Windows Form. MyFom has 3 GroupBoxes. Now I wanna update data from the textboxes in those 3 GroupBoxes. I have function Update1 for GroupBox1 to update table Table1, Update2 for GroupBox2 to update table Table2, Update3 for GroupBox3 to update table Table3. And there is a function TotalUpdate for MyForm. The function TotalUpdate comprises of Update1, Update2, and Update3.
6
13969
by: cylt | last post by:
Hello, I'm using a TransactionScope with a ADO.NET SqlClient and i get the error : System.Runtime.InteropServices.COMException (0x8004D024): The transaction manager has disabled its support for remote/network transactions. (Exception from HRESULT: 0x8004D024). Please enable DTC for network access in the security configuration for MSDTC using the Component Services Administrative tool. I've checked the configuration on both the client...
2
2552
by: Spottswoode | last post by:
Hi I have developed a client/server application in C# that worked perfectly in my office but not so perfectly after deploying it to our client. A little information about the architecture first: Both the client and server components are written in c#, windows forms for the front-end and the back end is exposed through IIS using webservices. We are using Impersonate in the web.config. The application is a warehouse inventory system,...
3
3108
by: BLUE | last post by:
Only SQL Server 2005 or also DB2, Oracle and MySQL? Thanks, Luigi.
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
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) {
3
8026
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(); }
6
3045
by: =?Utf-8?B?ZXhl?= | last post by:
Hi, I'm using TransactionScope to do a serie Insert, Update, Delete operations with the ExecuteNonQuery and some Selects with ExecuteScalar everything works fine with multiple connections in the same scope. Problem is that when i do two Selects with ExecuteReader (to fill datasets) it shows the folowing error: Network access for Distributed Transaction Manager (MSDTC) has been disabled. Please enable DTC for network access in the...
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
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...
0
9394
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...
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
9256
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
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...
0
4885
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2223
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.