C# 实体框架:提供程序未返回providermanifest实例
实体框架6.0.1 我的App.config:C# 实体框架:提供程序未返回providermanifest实例,c#,sql-server,entity-framework,ef-code-first,entity-framework-6,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 --> <
<?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>
创建了一个上下文,但当我试图获取任何实体或对数据库执行任何操作时,它抛出异常
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)
System.Configuration.ConfigurationErrorException:配置系统初始化失败
堆栈跟踪:
:/System.Configuration.ClientConfigurationSystem.onconfiggremoved(对象发送方,InternalConfigEventArgs e)
系统.Configuration.Internal.InternalConfigRoot.RemoveConfigImpl(字符串configPath,BaseConfigurationRecord configRecord)
:/System.Configuration.BaseConfigurationRecord.GetSectionRecursive(字符串configKey、布尔getLkg、布尔checkPermission、布尔getRuntimeObject、布尔RequestISHER、对象与结果、对象与结果EntimeObject)
:/System.Configuration.BaseConfigurationRecord.GetSection(字符串configKey)
:/System.Configuration.ConfigurationManager.GetSection(字符串sectionName)
of System.Xml.Schema.Parser..ctor(SchemaType SchemaType,XmlNameTable nameTable,SchemaNames SchemaNames,ValidationEventHandler)
:/System.Xml.Schema.XmlSchema.Read(XmlReader阅读器,ValidationEventHandler ValidationEventHandler)
of System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetHelper.AddXmlSchemaToSet(XmlSchemaSet schemaSet,xmlschemasource schemasource,HashSet`1 schemasAlreadyAdded)
of System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetPer.ComputeSchemaSet(SchemaDataModelation数据模型)
of System.Data.Entity.Core.Common.Utils.Memoizer`2.c_uudisplayClass2.b_u0()
of System.Data.Entity.Core.Common.Utils.Memoizer`2.Result.GetValue()
系统.数据.实体.核心.通用.实用工具.记忆器'2.评估(TArg arg)
of System.Data.Entity.Core.SchemaObjectModel.Schema.SomSchemaSetPer.GetSchemaSet(SchemaDataModelation数据模型)
of System.Data.Entity.Core.SchemaObjectModel.Schema.CreateXmlReaderSettings()
of System.Data.Entity.Core.SchemaObjectModel.Schema.Parse(XmlReader sourceReader,String sourceLocation)
of System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders,IEnumerable`1 SourceFilePath,SchemaDataModel,AttributeValueNotification providerNotification,AttributeValueNotification providerManifestTokenNotification,ProviderManifestRequired ProviderManifestRequired,IList`1&schemaCollection)
of System.Data.Entity.Core.SchemaObjectModel.SchemaManager.ParseAndValidate(IEnumerable`1 xmlReaders、IEnumerable`1 SourceFilePath、SchemaDataModel、DbProviderManifest providerManifest、IList`1和schemaCollection)
of System.Data.Entity.Core.SchemaObjectModel.SchemaManager.LoadProviderManifest(XmlReader、XmlReader、字符串位置、系统名称空间、模式和模式的布尔检查)
of System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest.Load(XmlReader)
of System.Data.Entity.Core.Common.DbXmlEnabledProviderManifest..ctor(XmlReader)
:/System.Data.Entity.SqlServer.SqlProviderManifest..ctor(字符串manifestoken)
:/System.Data.Entity.SqlServer.SqlProviderServices.GetDbProviderManifest(字符串版本提示)
of System.Data.Entity.Core.Common.DbProviderServices.GetProviderManifest(字符串标记)
除了内在的例外:
System.Configuration.ConfigurationErrorException:未知的配置节userSettings。(C:\\Users\\Tema\\AppData\\Local\\Mgr\\Mgr.vshost.exe\u Url\u slqi2aqp0duilazpy21vojhl3ssnjluh\\1.0.0.0\\user.config第3行)
堆栈跟踪:
of System.Configuration.ConfigurationSchemaErrors.Throwiferors(布尔ignoreLocal)
of System.Configuration.BaseConfigurationRecord.ThrowIfParseErrors(配置模式错误模式错误)
:/System.Configuration.ClientConfigurationSystem.onconfiggremoved(对象发送方,InternalConfigEventArgs e)
也许有人遇到过这个问题?谢谢。如果数据库的登录信息无效,或者服务器找不到或位于防火墙后面(基本上,您的程序无法连接到数据库),则会引发此异常。通常,它带有一个内部异常,它会告诉你更多关于所发生的事情。一定要检查一下这个。这个错误可能还有其他原因,但我认为这是最有可能的
另外,您使用的是SQL还是Windows身份验证?如果您使用的是SQL身份验证,请尝试向连接字符串中添加
integratedsecurity=False
。在我的情况下,我必须破解.EDMX文件并更改ProviderManifestToken=“2008”
更改了2012年和2008年的ProviderManifestToken属性值,所有操作正常
请记住将.edmx文件作为XML文件打开如果要将
ProviderManifestToken
设置为2012,请检查UseLegacyProvider
的值并确保将其设置为False 在我的例子中,我将Oracle与Oracle.ManagedDataAccess.EntityFramework.dll一起使用,
我使用版本12.2.20190115
可以解决这个问题:
可以尝试检查dll的版本是否正确。谢谢您的回复,我正在使用SQL身份验证并尝试使用
integrated security=False
但我总是遇到此错误您确定连接字符串中的数据源=
正确吗MyDb
听起来像是数据库名,但这应该是计算机名和服务器实例名(类似于mydbserver\sqlexpress
)。此外,请尝试使用相同的凭据连接到数据库,并使用类似SQLServerManagementStudio的工具从同一台计算机连接到数据库。如果这不起作用,这可能永远不会起作用。我确定,我通过服务器资源管理器连接到数据库,并刚刚复制了ConnectionString,然后刚刚更改了这个问题的servername\dbname\login\password。有吗
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)