简体   繁体   中英

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="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.

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.

这可能不是您的问题,但是如果您根本无法连接到数据库,也会发生此错误-我们的网络阻塞了端口1433。打开它,错误就消失了。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM