file access error on SQLCE database file after closing connection

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
 
D

Dexlex

This helped:

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

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