Is ExecuteNonQuery asynchronous?

N

Norvin Laudon

Hi,

I'm getting an error inserting data into Oracle: "ExecuteNonQuery requires
an open and available Connection. The connection's current state is Open,
Executing."

The "NonQuery" I'm trying to execute a simple INSERT statement (which
executes fine in SQL+). The INSERT statement executes properly 99% of the
time, but throws this error sometimes.

Perhaps ExecuteNonQuery executes asynchronously? Am I possibly trying to
execute a command before the previous one is finished? Is there some way I
can make sure the previous command is finished?

<code>
if (cn.State != ConnectionState.Open)
{
cn = new OleDbConnection(connStr);
cn.Open();
}

OleDbCommand cmd = new OleDbCommand(q,cn);
cmd.ExecuteNonQuery();

cmd.Dispose();
<\code>
 
P

Pablo Castro [MS]

Are you sharing the connection across multiple threads? or perhaps storing
the connection in global state (i.e. a static variable) and using it from
multiple places such as multiple asp.net pages? That might explain the
behavior you're seeing.

--
Pablo Castro
Program Manager - ADO.NET Team
Microsoft Corp.

This posting is provided "AS IS" with no warranties, and confers no rights.
 
N

Norvin Laudon

This hit me on the way to work, and your post confirms my idea.

The connection is a called by a remoting singleton, actually. So I suppose
it could be said that the connection is being shared across multiple
threads. I'm going to give each remoting client it's own connection, that
should clear up the problem.

Thanks for the reply,
Norvin
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top