System.Data.ProviderIncompatibleException was unhandled by user code

Message=The provider did not return a ProviderManifestToken string.

Or, how to run EF code-first without SQL Express.

I got the above exception being thrown when I started playing around with Entity Framework’s Code-First CTP5. The inner exception revealed the true problem:

ysod

The problem is that by default EF Code-First tries to create your database on a SQL Express instance.

I don’t run SQL Express, I run SQL Server Developer edition. The solution is to add a connection string for the code-first database to your web.config (even though this database doesn’t yet exist):


<connectionStrings>
 <add name="TweetContext" connectionString="Data Source=.; Initial Catalog=Tweet; Integrated Security=SSPI;" providerName="System.Data.SqlClient" />
 </connectionStrings>

Note that the name (TweetContext) must match the name of your class which derives from DbContext, i.e.


public class TweetContext : DbContext

And you have to specify the DB name, i.e Initial Catalog=Tweet, but that database should not already exist, as EF code-first will create it for you.

Advertisement

16 thoughts on “System.Data.ProviderIncompatibleException was unhandled by user code

  1. I had the same problem in a test project which required me to change App.config instead of web.config. I just write this in case someone in my same situation runs across your blog entry. :-)

  2. i have the same problem providerincompatibleexception ,how do you solve this ?

    i followed your example but what if you already have a database ?

    • What it is, is that you don’t have SQL Server Express installed and that is where EF Code first expects to find your server – at .\sqlexpress. I think that is what throws this exception. You need to modify your web.config as I explained.

  3. You are a god! I scoured the web for this fix. I really am liking this Code-First approach and I did not want to revert to SQL Express.

  4. You can also run into this issue when you are deploying and have:
    – A SQL server that is not accessible
    – An invalid username or password (or other credential) in the connection string

    I ran into these and figured I should share the other two reasons I’ve seen it. Thanks for the pointer in the right direction!

  5. Well, You not only saved my frustrations and hours. But gave me a hope that MVC, and learning new skills never sucks.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s