17

实体框架6.0.1 我的App.config:实体框架:提供程序未返回providermanifest实例

<?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> 

而且MyDataContext类使用EF:

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

    public MyDataContext() 
     : base("MyDataContext") 
    { 
    } 
} 

创建上下文,但当我试图得到任何实体或做任何事情与数据库它抛出异常

using (var db = new MyDataContext()) 
{ 
    var exists = db.Database.Exists(); 
} 

例外是

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

与内部异常:

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) 

也许任何人都遇到过这个问题吗?谢谢。

+2

我UserSettings'C刚刚删除的文件:\\ \\用户\\特马AppData的\\ \\本地经理\\ Mgr.vshost.exe_Url_slqi2aqp0duilazpy21vojhl3ssnjluh \ \ 1.0.0.0 \\ user.config' 它解决了我的问题 – Temaska

回答

9

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

另外,你使用SQL或Windows身份验证?如果您使用的是SQL身份验证,请尝试将integrated security=False添加到您的连接字符串中。

+0

感谢回复,我正在使用SQL身份验证,并尝试与'集成安全=假',但我总是有这个错误 – Temaska

+0

你确定你的'数据源='在连接字符串中是否正确? 'MyDb'听起来像数据库名称,但这应该是计算机的名称和服务器的实例(类似于'mydbserver \ sqlexpress')。另外,请尝试使用相同的凭据连接到数据库,并使用SQL Server Management Studio等相同的计算机连接到该数据库。如果这不起作用,这可能永远不会。 – Steve

+0

我敢肯定,我连接到数据库通过服务器资源管理器,只是复制ConnectionString,然后只是更改此问题的servername \ dbname \ login \ password .. – Temaska

59

在我而言,我不得不破解的.edmx文件并更改ProviderManifestToken = “2008”

  1. 打开Model.edmx编辑器
  2. 更改ProviderManifestToken = “2012” 到ProviderManifestToken =” 2008" 年

Model.edmx hack

+1

这对我有效。谢谢!你怎么知道这件事? – CowboyBebop

+2

令人惊叹。这工作。 :) 非常感谢!我也想知道你是怎么想出来的! – Greg

+0

这也适用于我,是否有解释这个问题? –

8

改变了ProviderManifestToken从2012年和2008年的属性值和所有工作得很好。

记得开.edmx文件的XML文件

相关问题