I'm trying to generate a SQL Server Express embedded database (.mdf) with code-first Entity Framework. It used to work fine but now, I just get over and over the same error, and I cannot identify the issue. The problem occurs on the initialization, it just hangs forever and if you look at intellitrace you can see some kind of loop of throw/catch statements all returning
"Unable to open the physical file "c:\gt\aspnetdb.mdf". Operating system error 2: "2 (failed to retrieve text for this error. Reason: 1815". Cannot attach the file "c:\gt\aspnetdb.mdf" as database 'WikDb'." (System.Data.SqlClient.SqlException)
UPDATE I also get the following error now just before the "unable to open physical file...."
Column 'InvariantName' is constrained to be unique. Value '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 initializing code
Database.SetInitializer(new DbInitializer()); //DropCreateDatabaseAlways<WikDb> intializer
Database.DefaultConnectionFactory.CreateConnection( "WikDb" );
WikDb db = new WikDb();
db.Database.Initialize( true );
Any help appreciated
Thank you,