开发者

How to configure ProviderManifestToken for EF CodeFirst in a Connection String

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="my开发者_高级运维ConnectionString" 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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜