ConnectionState problem

  • Thread starter Thread starter Nick Gilbert
  • Start date Start date
N

Nick Gilbert

Hi,

My application connects to an Access database when it is loaded, and
keeps the same connection open all the time.

There is logic in the code to ensure that the connection is
automatically opened the first time it is used:

if ((cmd.Connection.State == ConnectionState.Closed) ||
(cmd.Connection.State == ConnectionState.Broken)) cmd.Connection.Open();

However occasionally my application says this:

System.InvalidOperationException:
The connection is already Open (state=Connecting).

or it might say the same but with state=Executing.

But if the state is Executing, you can neither call .Open nor can you
execute a query. So how can I maintain an open connection without these
errors occuring?

To be honest, I don't understand why it is ever in the "Exectuting"
state, because it's a single threaded application and theres no way that
it can be doing more than one thing at once.

Thanks,

Nick...
 
Nick said:
Hi,

My application connects to an Access database when it is loaded, and
keeps the same connection open all the time.

There is logic in the code to ensure that the connection is
automatically opened the first time it is used:

if ((cmd.Connection.State == ConnectionState.Closed) ||
(cmd.Connection.State == ConnectionState.Broken)) cmd.Connection.Open();

However occasionally my application says this:

System.InvalidOperationException:
The connection is already Open (state=Connecting).

or it might say the same but with state=Executing.

But if the state is Executing, you can neither call .Open nor can you
execute a query. So how can I maintain an open connection without these
errors occuring?

To be honest, I don't understand why it is ever in the "Exectuting"
state, because it's a single threaded application and theres no way that
it can be doing more than one thing at once.

This is a known issue with the JET driver.

You could try to disable connection pooling in the connection string. See:
http://groups-beta.google.com/group...+already+Open"+Access&rnum=1#3dc5aab454b373a8

FB


--
 
Back
Top