473,320 Members | 1,978 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,320 software developers and data experts.

ADO .NET & transactions

[might be ot, if so pls. point me to the correct ng]

Hi @ll,

I have a problem using transactions in c#:

I have a class that implements all my database actions. In this class I have
-) The SqlConnection conn (which is opened in the ctor)
-) Some SqlCommand's (one of the we call cmd ) which are created like cmd =
conn.CreateCommand()
-) The statements are assigned cmd.CommandText = "SELECT x FROM y WHERE x =
h";
-) The statements are Prepared() cmd.Prepare

Then some functions are called and some commands are ExecuteReader()'ed.
Everything wors fine.
But then I have a methodthat does something like this (wihtin this class)

public updateInventory( string strProductCode )
{
SqlTransaction transact = conn.BeginTransaction(
System.Data.IsolationLevel.RepeatableRead );

cmd.Transaction = transact;
cmd.Parameters["@product_code"] = strProductCode;

cmd.ExecuteNonQuery();
}

The Problem is the line containing the BeginTransaction() - Statement. It
throws an System.InvalidOperationException
With the Details: "Begin transaction requires an open and available
connection. Current State: Open"

This confuses me, since the state is really open...
What is the real Problem?

TIA

Regards
Mario
Nov 15 '05 #1
2 3138
Hi Mario,

"Mario L. Eppinger" <no****@loe.at> wrote in message
news:10***************@knapp.co.at...
[might be ot, if so pls. point me to the correct ng]

Hi @ll,

I have a problem using transactions in c#:

I have a class that implements all my database actions. In this class I have -) The SqlConnection conn (which is opened in the ctor)
-) Some SqlCommand's (one of the we call cmd ) which are created like cmd = conn.CreateCommand()
-) The statements are assigned cmd.CommandText = "SELECT x FROM y WHERE x = h";
-) The statements are Prepared() cmd.Prepare

Then some functions are called and some commands are ExecuteReader()'ed.
Everything wors fine.
But then I have a methodthat does something like this (wihtin this class)

public updateInventory( string strProductCode )
{
SqlTransaction transact = conn.BeginTransaction(
System.Data.IsolationLevel.RepeatableRead );

cmd.Transaction = transact;
cmd.Parameters["@product_code"] = strProductCode;

cmd.ExecuteNonQuery();
}

The Problem is the line containing the BeginTransaction() - Statement. It
throws an System.InvalidOperationException
With the Details: "Begin transaction requires an open and available
connection. Current State: Open"

This confuses me, since the state is really open...
What is the real Problem?


A guess: Is there perhaps a SqlDataReader object that is open and
attached to the connection. I think DataReaders tie up a connection as long
as they are open.

Regards,
Dan
Nov 15 '05 #2
Thanks Daniell! That's it!
Best Regards

Mario

"Daniel Pratt" <ko******************@hotmail.com> schrieb im Newsbeitrag
news:uJ**************@tk2msftngp13.phx.gbl...
Hi Mario,

"Mario L. Eppinger" <no****@loe.at> wrote in message
news:10***************@knapp.co.at...
[might be ot, if so pls. point me to the correct ng]

Hi @ll,

I have a problem using transactions in c#:

I have a class that implements all my database actions. In this class I have
-) The SqlConnection conn (which is opened in the ctor)
-) Some SqlCommand's (one of the we call cmd ) which are created like cmd =
conn.CreateCommand()
-) The statements are assigned cmd.CommandText = "SELECT x FROM y WHERE
x =
h";
-) The statements are Prepared() cmd.Prepare

Then some functions are called and some commands are ExecuteReader()'ed.
Everything wors fine.
But then I have a methodthat does something like this (wihtin this
class)
public updateInventory( string strProductCode )
{
SqlTransaction transact = conn.BeginTransaction(
System.Data.IsolationLevel.RepeatableRead );

cmd.Transaction = transact;
cmd.Parameters["@product_code"] = strProductCode;

cmd.ExecuteNonQuery();
}

The Problem is the line containing the BeginTransaction() - Statement. It throws an System.InvalidOperationException
With the Details: "Begin transaction requires an open and available
connection. Current State: Open"

This confuses me, since the state is really open...
What is the real Problem?


A guess: Is there perhaps a SqlDataReader object that is open and
attached to the connection. I think DataReaders tie up a connection as

long as they are open.

Regards,
Dan

Nov 15 '05 #3

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

Similar topics

1
by: Alexander Ross | last post by:
Lets say I want to execute 3 postgresql queries in a row based on the inputs in a php form...Here's the catch though. What happens if #1 and #2 execute perfectly, but #3 fails for one reason or...
4
by: Leaf | last post by:
Greetings, I've been reading with interest the threads here on deadlocking, as I'm finding my formerly happy app in a production environment suddenly deadlocking left and right. It started...
5
by: princevejita1 | last post by:
Hello I have problem with my MySQL server and transactions. I installed MySQL server 5.0.11 with MySQL administrator & MySql Query Browser on Win XP Prof. I would like to use transactions, so I...
7
by: simon | last post by:
Hi I know this has been done to death....but obviously at some point in the dim and distant past! I wish to program a retail database for my shop, I have trawled many forums and I only manage...
9
by: Greg Gursky | last post by:
Hello: I'm doing some planning on a potential project with which I need some help. The database at the focus of this question is a MS Access database that is currently accessed by DAO from a...
1
by: Jim Bancroft | last post by:
Hi everyone, I'm running into a problem with my ASP.Net application. I've just created a new aspx page which uses some new components of mine that inherit from ServicedComponent and are...
3
by: Lada 'Ray' Lostak | last post by:
Hello ppl, Imagine some online system, based on PgSql. There are 'many' parts which depends on each other. I will give small example, but instead of simple table imagine changing tenths various...
16
by: ARC | last post by:
Hello all, So I'm knee deep in this import utility program, and am coming up with all sorts of "gotcha's!". 1st off. On a "Find Duplicates Query", does anyone have a good solution for...
0
by: Vinod Sadanandan | last post by:
STANDBY DATABASE MONITORING & PROTECION MODES (9iR2) This document is written for understanding and monitoring standby database configured with diffrent protection modes . MAXIMUM PROTECTION ...
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...
1
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)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
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....

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.