Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Transaction error

Reply
Thread Tools

Transaction error

 
 
Chris Zopers
Guest
Posts: n/a
 
      05-12-2009
Hello,

I've developed a web application. The application uses one static
connection object. Some methods use Transactions. Everything works fine,
except when several users start using the webapplication at the same
time. I often get the following message:

"Execute requires the Command object to have a Transaction object when
the Connection object assigned to the Command is in a pending local
transaction. The Transaction property of the Command has not been
initialized."

I think it has something to do with using one static connection for all
users, but do not know this for sure. I tried locking the
connection-code with the Lock statement, but the error still occurs.

The webserver has multiple processors, my local machine has only one
processor. Can this have something to do with it? I do not know what can
cause this, the code seems to be correct, no errors occur when the code
is run by one user. We use Oracle 9i as the database.

Greetings,
Chris

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-12-2009
When you execute a query on a Command object within a transaction, you need
to get the Transaction object for your connection and assign it the
Transaction property of your Command. Something like this:

OracleTransaction myTransaction = myConnection.BeginTransaction();
myCommand.Transaction = myTransaction;
myCommand.ExecuteNonQuery();


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Chris Zopers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hello,
>
> I've developed a web application. The application uses one static
> connection object. Some methods use Transactions. Everything works fine,
> except when several users start using the webapplication at the same
> time. I often get the following message:
>
> "Execute requires the Command object to have a Transaction object when
> the Connection object assigned to the Command is in a pending local
> transaction. The Transaction property of the Command has not been
> initialized."
>
> I think it has something to do with using one static connection for all
> users, but do not know this for sure. I tried locking the
> connection-code with the Lock statement, but the error still occurs.
>
> The webserver has multiple processors, my local machine has only one
> processor. Can this have something to do with it? I do not know what can
> cause this, the code seems to be correct, no errors occur when the code
> is run by one user. We use Oracle 9i as the database.
>
> Greetings,
> Chris
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4068 (20090512) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4068 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



 
Reply With Quote
 
 
 
 
Chris Zopers
Guest
Posts: n/a
 
      05-13-2009
This is the situation at the moment:

1) There is a webapplication with a lot of different methods that access
an Oracle database. These methods do not interact with each other, each
method performs its own tasks.
2) Some methods use a transaction, some execute only a single SQL
statement and therefore do not use a transaction.
3) All make use of one static connection object.

When one user uses the application, everything works fine. There is no
error in code or transactions that do not work.

When other users start using the application at the same time, sometimes
the error mentioned before occurs. This error can occur in methods that
do not even have anything to do with methods that use transactions.

Hope someone recognizes this problem....

Greetings,
Christian

*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
Eliyahu Goldin
Guest
Posts: n/a
 
      05-13-2009
I suggest you to re-think the idea of using a static connection object. You
can safely rely on connection pooling that you get out of box with ASP.NET.
A good practice is to close the connection at the end of every data access.
The connection pooling will take care of optimizing it for you.


--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin


"Chris Zopers" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> This is the situation at the moment:
>
> 1) There is a webapplication with a lot of different methods that access
> an Oracle database. These methods do not interact with each other, each
> method performs its own tasks.
> 2) Some methods use a transaction, some execute only a single SQL
> statement and therefore do not use a transaction.
> 3) All make use of one static connection object.
>
> When one user uses the application, everything works fine. There is no
> error in code or transactions that do not work.
>
> When other users start using the application at the same time, sometimes
> the error mentioned before occurs. This error can occur in methods that
> do not even have anything to do with methods that use transactions.
>
> Hope someone recognizes this problem....
>
> Greetings,
> Christian
>
> *** Sent via Developersdex http://www.developersdex.com ***
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 4069 (20090512) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
>
>



__________ Information from ESET NOD32 Antivirus, version of virus signature database 4069 (20090512) __________

The message was checked by ESET NOD32 Antivirus.

http://www.eset.com



 
Reply With Quote
 
Chris Zopers
Guest
Posts: n/a
 
      05-13-2009
Thanks for your answer.

I noticed a weird thing. Each error occurs in methods that use the
ExecuteScalar method. I changed every method that uses ExecuteScalar
into ExecuteReader and use the first value of the first row from the
Reader. Now the error has disappeared! Strange huh?

Greetings,
Chris





*** Sent via Developersdex http://www.developersdex.com ***
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Win2003 SP1 error: "New transaction cannot enlist in the specified transaction coordinator" Vencz Istv?n ASP General 2 05-02-2005 05:53 AM
Error in OLEDB Transaction Eitan ASP .Net 4 04-10-2005 02:56 AM
DTS Transformation Error: "Transaction context in use by another session." Axel Dahmen ASP .Net 1 02-07-2005 12:35 AM
Distributed Transaction Error =?Utf-8?B?SnVsaWFuIFNhbno=?= ASP .Net 0 11-22-2004 05:49 PM
Error in Database Transaction Vivek ASP .Net 0 07-08-2003 09:25 PM



Advertisments