I am trying to create an embedded SQL Server Express database (.mdf) with a code-based Entity Framework. It worked fine, but now I just go over to the same error and I can not determine the problem. The problem occurs during initialization, it just freezes forever, and if you look at intellitrace, you can see some kind of loop of throw / catch statements that return
“Unable to open the physical file“ c: \ gt \ aspnetdb.mdf. ”System error 2:“ 2 (could not get the text for this error Cause: 1815. ”Cannot attach the file“ c: \ gt \ aspnetdb.mdf ”to as the database 'WikDb'. "(System.Data.SqlClient.SqlException)
UPDATE I also get the following error now before "inability to open a physical file ..."
The column "InvariantName" is limited to unique. The cost of 'System.Data.SqlClient' is already present.
END UPDATE
Here is my app.config
<configuration> <system.data> <DbProviderFactories> <remove invariant="System.Data.SqlServerCe.4.0" /> <add name="Microsoft SQL Server Compact Data Provider 4.0" invariant="System.Data.SqlServerCe.4.0" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=4.0.0.0"/> </DbProviderFactories> </system.data> <connectionStrings> <add name="WikDb" connectionString="data source=.\SQLEXPRESS;Integrated Security=True; database=WikDb;AttachDBFilename=c:\gt\aspnetdb.mdf; User Instance=True" providerName="System.Data.SqlClient" /> </connectionStrings> </configuration>
And here is my initialization code
Database.SetInitializer(new DbInitializer()); //DropCreateDatabaseAlways<WikDb> intializer Database.DefaultConnectionFactory.CreateConnection( "WikDb" ); WikDb db = new WikDb(); db.Database.Initialize( true );
Any help appreciated
Thanks,
source share