Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Release file lock on Access database after closing OleDbConnection? 1

Status
Not open for further replies.

dalchri

Programmer
Apr 19, 2002
608
US
I need to compact and repair an Access database but I can't get the .ldb file to go away or the file lock to release.

I use the following code to close my connection:

Code:
//This connection is opened elsewhere and used to query
//the database before it gets to this point
OleDbConnection con;

con.Close();
con.Dispose();

After the above code executes, the .ldb file persists and I cannot compact repair the database.

Any ideas?
 
You need to wait for the garbage collection cycle to run.

If this code is the last thing to run in your program, you can force a cycle to run with
Code:
using System;

GC.Collect();
You shouldn't over-use this, as it will cause noticable delays in your program when it runs.

Chip H.


____________________________________________________________________
Click here to learn Ways to help with Tsunami Relief
If you want to get the best response to a question, please read FAQ222-2244 first
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top