OleDBConnection.Close() does not release MS Access database

E

Evgeny Zoldin

Hi ALL,

I do in C# the following:

bool DoSomething(){
OleDbConnection conn = new OleDbConnection( "... connection string to
MS_Access.mdb ... ");

/* do what I need using OleDbDataAdapter, DataTable etc... */

conn.Close();

GC.Collect(); // !!!!! - gives no effect for the the following
statements

File.Move( ".. old location..." + MS_Access.mdb, "...new location..." +
MS_Access.mdb); // -- throws exception !!!!!
// System.IO.IOException: The process cannot access the file ""... new
location..." + MS_Access.mdb" because it is being used by another process.
// But <"... new location..." + MS_Access.mdb> does not exist at all !!!
// and I see that <""... old location..." + MS_Access.ldb"> still eists,
i.e. call conn.Close() does not release the file
.......
}

If I call just before File.Move(...)

MessageBox.Show( " message " );

than the file <""... old location..." + MS_Access.ldb"> disappears and
<""... old location..." + MS_Access.mdb"> being released and File.Move(...)
works fine.

What the reason of that behaviour? As I did the similar in VB6 by means of
ADO it worked correct without MsgBox(...)...

Thanx for any help
Evgeny
 
M

Miha Markic [MVP C#]

Hi Evheny,

I think it has to do with connection pooling.
The connection is still active for something like 60 seconds after you close
it.
If you don't want to use pooling, add "OLE DB Services=-4;" to connection
string.
 
P

Paul Clement

On Thu, 15 Jul 2004 09:14:37 +0200, "Miha Markic [MVP C#]" <miha at rthand com> wrote:

¤ Hi Evheny,
¤
¤ I think it has to do with connection pooling.
¤ The connection is still active for something like 60 seconds after you close
¤ it.
¤ If you don't want to use pooling, add "OLE DB Services=-4;" to connection
¤ string.

Jet OLEDB does not support connection pooling. It's just file based database share.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
E

Evgeny Zoldin

Thanks a lof!


Paul Clement said:
¤ Hi Evheny,
¤
¤ I think it has to do with connection pooling.
¤ The connection is still active for something like 60 seconds after you close
¤ it.
¤ If you don't want to use pooling, add "OLE DB Services=-4;" to connection
¤ string.

Jet OLEDB does not support connection pooling. It's just file based database share.


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 

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