Change database on runtime

May 11, 2011 at 9:47 AM


In my project I have to change the database on runtime.

So, I change the connectionString and after I want to rename the old database, but I have the 'file in use by another process' exception.

Is there a way to close all connections and free the file ?



May 11, 2011 at 10:10 AM

I generate a class called EntityBase which contains a singleton instance of the SqlCeConnection called Connection, call Dispose() on this and set it to NULL. This should release handle to the SQLCE database file. I only use one connection to the database, and never close it (for performance reasons)

Hope this helps

May 12, 2011 at 6:25 AM

It's work perfectly!

Thank you so much!

I've totally missed that property.