Entity Framework: The provider did not return a providermanifest instance

Tem*_*ska 18 c# sql-server entity-framework ef-code-first entity-framework-6

实体框架6.0.1我的App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <configSections>
    <!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
    <section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
  </configSections>
  <startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" />
  </startup>
  <entityFramework>
    <defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
    <providers>
      <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
    </providers>
  </entityFramework>
  <connectionStrings>
    <add name="MyDataContext" connectionString="Data Source=MyDb;Initial Catalog=mycatalog;Persist Security Info=True;User ID=admin;Password=123;MultipleActiveResultSets=True"
      providerName="System.Data.SqlClient" />
  </connectionStrings>
</configuration>
Run Code Online (Sandbox Code Playgroud)

MyDataContext使用EF类:

public partial class MyDataContext: DbContext
{
   static MyDataContext()
   {
       Database.SetInitializer<MyDataContext>(null);
   }

   public MyDataContext()
       : base("MyDataContext")
   {
   }
}
Run Code Online (Sandbox Code Playgroud)

创建了一个上下文,但是当我尝试获取任何实体或对数据库执行任何操作时,它会抛出异常

using (var db = new MyDataContext())
{
    var exists = db.Database.Exists();
}
Run Code Online (Sandbox Code Playgroud)

例外是

System.Data.ProviderIncompatibleException: The provider did not return a providermanifest instance
StackTrace:
   in System.Data.Common.DbProviderServices.GetProviderManifest(String manifestToken)
   in System.Data.Entity.ModelConfiguration.Utilities.DbConnectionExtensions.GetProviderInfo(DbConnection connection, DbProviderManifest& providerManifest)
   in System.Data.Entity.DbModelBuilder.Build(DbConnection providerConnection)
   in System.Data.Entity.Internal.LazyInternalContext.CreateModel(LazyInternalContext internalContext)
   in System.Data.Entity.Internal.RetryLazy`2.GetValue(TInput input)
   in System.Data.Entity.Internal.LazyInternalContext.InitializeContext()
   in System.Data.Entity.Internal.InternalContext.CreateObjectContextForDdlOps()
   in System.Data.Entity.Database.Exists()
Run Code Online (Sandbox Code Playgroud)

内部异常:

System.Configuration.ConfigurationErrorException: Configuration system failed to initialize
StackTrace:
   ? System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
   ? System.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(String configPath, BaseConfigurationRecord configRecord)
   ? System.Configuration.BaseConfigurationRecord.GetSectionRecursive(String configKey, Boolean getLkg, Boolean checkPermission, Boolean getRuntimeObject, Boolean requestIsHere, Object& result, Object& resultRuntimeObject)
   ? System.Configuration.BaseConfigurationRecord.GetSection(String configKey)
   ? System.Configuration.ConfigurationManager.GetSection(String sectionName)
   ? System.Xml.Schema.Parser..ctor(SchemaType schemaType, XmlNameTable nameTable, SchemaNames schemaNames, ValidationEventHandler eventHandler)
   ? System.Xml.Schema.XmlSchema.Read(XmlReader reader, ValidationEventHandler validationEventHandler)
   ? System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.AddXmlSchemaToSet(XmlSchemaSet schemaSet, XmlSchemaResource schemaResource, HashSet`1 schemasAlreadyAdded)
   ? System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.ComputeSchemaSet(SchemaDataModelOption dataModel)
   ? System.Data.Entity.Core.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
   ? System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()
   ? System.Data.Entity.Core.Common.Utils.Memoizer`2.Evaluate(TArg arg)
   ? System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.GetSchemaSet(SchemaDataModelOption dataModel)
   ? System.Data.Entity.Core.SchemaObjectModel.Schema.CreateXmlReaderSettings()
   ? System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(XmlReader sourceReader, String sourceLocation)
   ? System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, AttributeValueNotification providerNotification, AttributeValueNotification providerManifestTokenNotification, ProviderManifestNeeded providerManifestNeeded, IList`1& schemaCollection)
   ? System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders, IEnumerable`1 sourceFilePaths, SchemaDataModelOption dataModel, DbProviderManifest providerManifest, IList`1& schemaCollection)
   ? System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest(XmlReader xmlReader, String location, Boolean checkForSystemNamespace, Schema& schema)
   ? System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader reader)
   ? System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor(XmlReader reader)
   ? System.Data.Entity.SqlServer.SqlProviderManifest..ctor(String manifestToken)
   ? System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest(String versionHint)
   ? System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(String manifestToken)

and it with inner exception:

System.Configuration.ConfigurationErrorException: Unknown configuration section  userSettings. (C:\\Users\\Tema\\AppData\\Local\\Mgr\\Mgr.vshost.exe_Url_slqi2aqp0duilazpy21vojhl3ssnjluh\\1.0.0.0\\user.config line 3)
StackTrace:
   ? System.Configuration.ConfigurationSchemaErrors.ThrowIfErrors(Boolean ignoreLocal)
   ? System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(ConfigurationSchemaErrors schemaErrors)
   ? System.Configuration.ClientConfigurationSystem.OnConfigRemoved(Object sender, InternalConfigEventArgs e)
Run Code Online (Sandbox Code Playgroud)

也许有人遇到过这个问题?谢谢.

mit*_*aka 64

在我的情况下,我不得不破解.EDMX文件并更改ProviderManifestToken ="2008"

  1. 在编辑器中打开Model.edmx
  2. 将ProviderManifestToken ="2012"更改为ProviderManifestToken ="2008"

Model.edmx hack

  • 惊人.这很有效.:) 非常感谢!我也想知道你是怎么想的! (2认同)

Ste*_*eve 9

如果数据库的登录信息无效或者未找到服务器或位于防火墙后面(基本上,您的程序无法连接到数据库),则可能抛出此异常.通常它会附带一个内部异常,它会告诉您更多有关发生的事情的信息.一定要检查一下.这个错误可能还有其他原因,但我认为这是最有可能的.

此外,您使用SQL或Windows身份验证?如果您正在使用SQL身份验证,请尝试添加integrated security=False到您的连接字符串.


小智 8

从2012年和2008年更改了ProviderManifestToken属性值,并且一切正常.

请记住将.edmx文件作为XML文件打开