SQL CE 4.0 - Exception - Cannot drop the database, because you do not have permission or it is being accessed by some other process

StackOverflow https://stackoverflow.com/questions/4438008

Pergunta

HI,

I have followed through an example on the net of using SQLCE 4 with MVC 3, using NuGet.

Everything seems to working fine for most users, but everynow and again I get this error. Cannot drop the database, because you do not have permission or it is being accessed by some other process.

I'm not actually able to reproduce as it doesnt happen often, I pulled this from my logs.

Anyone know how I can resolve this?

Thx

The code in the AppStart_SQLECEntityFramework.cs

public static class AppStart_SQLCEEntityFramework {
    public static void Start() {
        Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", HostingEnvironment.MapPath("~/App_Data/"), "");

        Database.SetInitializer(new RecreateDatabaseIfModelChanges<OCCardMailout.Domain.OCCardContext>());
    }
}
Foi útil?

Solução

Are you using EF4 CodeFirst CTP ? There is a bug in SQLCE4 CTP2, that can cause CreateDatabaseOnlyIfNotExist to fail - see http://erikej.blogspot.com/2010/10/sql-server-compact-40-ctp2-released.html

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top