J
Jon
I have seen a few threads mentioning this problem, but none of them
have offered a solution that works for me. I have an application that
creates an OleDbConnection to a Microsoft Access 2003 database. When
the application is done with the connection, I call the Close() method
on the connection to free up the database resource. After reading
other threads, I even added "OLE DB Services=-4;" to my connection
string to prevent connection pooling, although I gather that it should
have no effect on a local MDB data source. In any case, the
application then attempts to move the database file (in preparation
for a JDO.CompactDatabase call, which seems to be necessary for some
reason), and I get an error because the database file is supposedly
still in use. I tried adding calls to OleDbConnection.Dispose() and
GC.Collect() in desperation, but nothing seems to work.
Here's the offending code:
dbConn = new OleDbConnection();
dbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;OLE DB
Services=-4;Data Source=" + dbPath;
dbConn.Open();
//
// Use the connection here...
//
// Disconnect from the database
dbConn.Close();
Debug.Assert(dbConn.State == ConnectionState.Closed);
dbConn.Dispose();
dbConn = null;
GC.Collect();
// Prepare to repair the database (due to occasional complex join
problems)
File.Move(dbPath, "c:\\temp_location.mdb"); <---- ***** Error occurs
here *****
Oddly enough, the error indicates that the target file for the move
cannot be accessed:
The process cannot access the file "c:\temp_location.mdb" because it
is being used by another process.
I can see that an LDB file is created when I call dbConn.Open, but it
does not disappear until the application is closed, no matter what I
do to that dbConn object. Does anyone have any suggestions?
Thanks,
Jon
have offered a solution that works for me. I have an application that
creates an OleDbConnection to a Microsoft Access 2003 database. When
the application is done with the connection, I call the Close() method
on the connection to free up the database resource. After reading
other threads, I even added "OLE DB Services=-4;" to my connection
string to prevent connection pooling, although I gather that it should
have no effect on a local MDB data source. In any case, the
application then attempts to move the database file (in preparation
for a JDO.CompactDatabase call, which seems to be necessary for some
reason), and I get an error because the database file is supposedly
still in use. I tried adding calls to OleDbConnection.Dispose() and
GC.Collect() in desperation, but nothing seems to work.
Here's the offending code:
dbConn = new OleDbConnection();
dbConn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;OLE DB
Services=-4;Data Source=" + dbPath;
dbConn.Open();
//
// Use the connection here...
//
// Disconnect from the database
dbConn.Close();
Debug.Assert(dbConn.State == ConnectionState.Closed);
dbConn.Dispose();
dbConn = null;
GC.Collect();
// Prepare to repair the database (due to occasional complex join
problems)
File.Move(dbPath, "c:\\temp_location.mdb"); <---- ***** Error occurs
here *****
Oddly enough, the error indicates that the target file for the move
cannot be accessed:
The process cannot access the file "c:\temp_location.mdb" because it
is being used by another process.
I can see that an LDB file is created when I call dbConn.Open, but it
does not disappear until the application is closed, no matter what I
do to that dbConn object. Does anyone have any suggestions?
Thanks,
Jon