OracleConnection.BeginTransaction() calls OracleCommand.ExecuteNonQuery() internally?

  • Thread starter Thread starter Sanjay
  • Start date Start date
S

Sanjay

Hi

I'm trying to use OracleConnection.BeginTransaction() to create an
OracleTransaction object to assign to the transaction property of my
OracleCommand object. I get this exception ...

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

Stack Trace ...

at System.Data.OracleClient.OracleCommand.Execute(OciHandle
statementHandle, CommandBehavior behavior, Boolean isReader, Boolean
needRowid, OciHandle& rowidDescriptor, ArrayList&
refCursorParameterOrdinals)
at System.Data.OracleClient.OracleCommand.Execute(OciHandle
statementHandle, CommandBehavior behavior, Boolean needRowid,
OciHandle& rowidDescriptor)
at
System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean
needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
at System.Data.OracleClient.OracleTransaction..ctor(OracleConnection
connection, IsolationLevel isolationLevel)
at
System.Data.OracleClient.OracleConnection.BeginTransaction(IsolationLevel
il)
at MyApp.MyMethod()

It seems to be internally calling OracleCommand.ExecuteNonQuery() which
requires a transaction object !

Is there any way around this problem?

Thanks.

- Sanjay
 
Sanjay said:
Hi

I'm trying to use OracleConnection.BeginTransaction() to create an
OracleTransaction object to assign to the transaction property of my
OracleCommand object. I get this exception ...

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

Stack Trace ...

at System.Data.OracleClient.OracleCommand.Execute(OciHandle
statementHandle, CommandBehavior behavior, Boolean isReader, Boolean
needRowid, OciHandle& rowidDescriptor, ArrayList&
refCursorParameterOrdinals)
at System.Data.OracleClient.OracleCommand.Execute(OciHandle
statementHandle, CommandBehavior behavior, Boolean needRowid,
OciHandle& rowidDescriptor)
at
System.Data.OracleClient.OracleCommand.ExecuteNonQueryInternal(Boolean
needRowid, OciHandle& rowidDescriptor)
at System.Data.OracleClient.OracleCommand.ExecuteNonQuery()
at
System.Data.OracleClient.OracleTransaction..ctor(OracleConnection
connection, IsolationLevel isolationLevel) at
System.Data.OracleClient.OracleConnection.BeginTransaction(IsolationLe
vel il)
at MyApp.MyMethod()

It seems to be internally calling OracleCommand.ExecuteNonQuery()
which requires a transaction object !

Correct, as BeginTransaction() actually simply executes BEGIN TRANS
name on the server, over the OPEN connection the command is associated
with.

This thus means that the connection associated with the command
shouldn't already be in a transaction, though the exception suggests it
is.

Frans
Is there any way around this problem?


--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 
Hi Miha

In MyClass.MyMethod() I have code like ...

OracleTransaction MyTran = MyConn.BeginTransaction();
MyCommand.Transaction = MyTran;

MyConn is a private member (type OracleConnection) of MyClass, shared
by many methods.
MyCommand is also a private member (type OracleCommand) of MyClass,
shared by many methods.
MyTran is local to MyMethod()

The exception gets thrown upon calling MyConn.BeginTransaction().

Is there a way around this problem? What is the recommended way to do
transactions using OracleClient library?

Thanks

- Sanjay
 
Back
Top