1

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:

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

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.

0xbadf00d
  • 17,405
  • 15
  • 67
  • 107
  • Possible duplicate of [How to configure ProviderManifestToken for EF Code First](http://stackoverflow.com/questions/4741499/how-to-configure-providermanifesttoken-for-ef-code-first) – Michael Freidgeim Mar 27 '17 at 04:23

2 Answers2

3

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).

Edit:

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.

Ladislav Mrnka
  • 360,892
  • 59
  • 660
  • 670
  • Good point. I wonder if it would be possible to provide the connection string & provider type (for sql ce 4) with SqlConnectionFactory. – Teoman Soygul Jul 25 '11 at 13:04
  • I don't think so because `SqlConnectionFactory` is tightly coupled with `SqlConnection` and it results in incorrect provider manifest token for SQL Server CE. `System.Data.Entity.Infrastructure.SqlCeConnectionFactory` should be able to create correct connection type for both SQL Server CE 3.5 and 4.0. – Ladislav Mrnka Jul 25 '11 at 13:11
  • 1
    Yep, just tried it and `Database.DefaultConnectionFactory = new SqlCeConnectionFactory("System.Data.SqlServerCe.4.0", "", "Data Source=|DataDirectory|Database.sdf");` works with CE4. Another good point. – Teoman Soygul Jul 25 '11 at 13:19
  • @ Ladislav Mrnka - You're right. Actually, I specified a bad `data source`. The Exception was misleading. Thanks. – 0xbadf00d Jul 25 '11 at 15:24
0

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.

Rob Church
  • 6,783
  • 3
  • 41
  • 46