Home All Groups Group Topic Archive Search About

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

Author
17 Apr 2006 5:04 AM
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

Author
17 Apr 2006 6:48 AM
Miha Markic [MVP C#]
Hi Sanjay,

What does your code look like?

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Show quote
"Sanjay" <sv0***@gmail.com> wrote in message
news:1145250257.581177.6960@i39g2000cwa.googlegroups.com...
> 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
>
Author
17 Apr 2006 8:34 AM
Sanjay
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
Author
17 Apr 2006 7:28 AM
Frans Bouma [C# MVP]
Sanjay wrote:

Show quote
> 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#)
------------------------------------------------------------------------

AddThis Social Bookmark Button