In a Connection String, how to setup ProviderManifestToken for EF CodeFirst

c# connection-string ef-code-first entity-framework


Currently, I'm passing a database name to the constructor of DbContext. In the connectionStrings section of my App.Config file, I've added a connection string and specified the provider name:

    <add name="myConnectionString" connectionString="[..]" providerName="System.Data.SqlClient"/>

Now, I want to get the connection string from an other kind of configuration source, but a ProviderIncompatibleException is thrown. The exception contains the following message:

"The provider did not return a providermanifesttoken string".

So, how can I specify the provider name in a connection string? Currently my string contains data source, database and some other configuration settings.

7/25/2011 12:06:37 PM

Accepted Answer

Provider is defined by the type of a connection and the connection is created by its connection factory which is set in static property Database.DefaultConnectionFactory. Default value of this property is SqlConnectionFactory so unless you are connecting to a different database server (for example SQL Server CE) it should simply work. If it doesn't make sure that your connection string is correct. This exception is sometimes fired if EF cannot connect to SQL server (I think I saw this exception either with invalid credentials, invalid database name or invalid SQL server instance name).


For completeness: The connection factory is used only if you pass connection string to the context. You can also passed whole connection instance and connection factory will not be used. Provider manifest token will be inferred from the type of the connection you will pass to the context.

7/25/2011 1:33:22 PM

Popular Answer

This may not be your problem, but this error also occurs if you simply can't connect to your database - our network was blocking port 1433. Opened it up, error goes away.

Related Questions


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow