MVC 3, EF Code First and SQL CE: Putting it all together

If I don’t write about this incident, I’ll inevitably repeat it.  So here we go:

Problem:
SQL CE database was not getting created when using using Entity Framework’s Code First paradigm within an MVC application.

Details:
Initial error stated:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 – Error Locating Server/Instance Specified)

However, the Inner Exception specified:

ProviderIncompatibleException: The provider did not return a ProviderManifestToken string.

Resolution:
Essentially, what I was lacking was a Connection String to tell Entity Framework where to create the Database.

I used the following code in the root-level Web.config file to remedy the error:

<add name="SalesQuoteDB" connectionString="Data Source=|DataDirectory|SalesQuote.sdf" providerName="System.Data.SqlServerCe.4.0"/>

Now all seems well with the world.

Advertisements