file access error on SQLCE database file after closing connection

  • Thread starter Thread starter Dexlex
  • Start date Start date
D

Dexlex

I'm using SQL Server CE 2.0 with .NetCF 1.0 SP3. I open the database
connection at program start and leave it open until end. Now, at some point
in the application, I want to save the database SDF file to a different
location and at another point I want to compact the database. In order to do
that, I have to close the connection temporarily.

After calling Close() and Dispose() of the SqlCeConnection, I sometimes
can't immediately access the file for copying or for compacting and get a
file sharing violation. Obviously, the file is still blocked. When I
repeatedly retry to access the file, I'm successful after a while. But
sometimes even waiting for 2 minutes is not enough.

What can I do?

Thanks for helping!

Dex
 
This helped:

....
connection.Close();
connection.Dispose();
GC.Collect();
GC.WaitForPendingFinalizers();
GC.Collect();
File.Copy (dbfilename, ...
 
Back
Top