C# 实体框架:提供者未返回 providermanifest 实例
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19574981/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Entity Framework: The provider did not return a providermanifest instance
提问by Temaska
Entity Framework 6.0.1 my App.config:
实体框架 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>
And MyDataContext
class for using EF:
和MyDataContext
使用 EF 的类:
public partial class MyDataContext: DbContext
{
static MyDataContext()
{
Database.SetInitializer<MyDataContext>(null);
}
public MyDataContext()
: base("MyDataContext")
{
}
}
A context is created, but when I tried to get any entity or do anything with Database it throw exception
创建了上下文,但是当我尝试获取任何实体或对数据库执行任何操作时,它会抛出异常
using (var db = new MyDataContext())
{
var exists = db.Database.Exists();
}
exception is
例外是
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()
with inner exception:
内部例外:
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)
Maybe anyone encountered this problem? Thank you.
也许有人遇到过这个问题?谢谢你。
采纳答案by Steve
This exception can be thrown if the login information for the database isn't valid or if the server isn't found or is behind a firewall (basically, your program can't connect to the database). Usually it comes with an inner exception that will tell you more about what happened. Be sure to check for this. There may be other causes for this error, but that's the most likely I think.
如果数据库的登录信息无效,或者服务器未找到或位于防火墙后面(基本上,您的程序无法连接到数据库),则可能会引发此异常。通常它带有一个内部异常,它会告诉你更多关于发生的事情。请务必检查这一点。此错误可能还有其他原因,但我认为这是最有可能的原因。
Also, are you using SQL or Windows authentication? If you're using SQL authentication, try adding integrated security=False
to your connection string.
另外,您使用的是 SQL 还是 Windows 身份验证?如果您使用 SQL 身份验证,请尝试添加integrated security=False
到您的连接字符串。
回答by mitaka
In my case I had to hack the .EDMX file and change the ProviderManifestToken="2008"
就我而言,我不得不破解 .EDMX 文件并更改 ProviderManifestToken="2008"
- Open your Model.edmx in editor
- Change the ProviderManifestToken="2012" to ProviderManifestToken="2008"
- 在编辑器中打开 Model.edmx
- 将 ProviderManifestToken="2012" 更改为 ProviderManifestToken="2008"
回答by Thoufeeq S L
Changed the ProviderManifestToken attribute value from 2012 and 2008 and all worked fine.
从 2012 年和 2008 年更改了 ProviderManifestToken 属性值,一切正常。
Remember to open the .edmx file as a XML file
请记住将 .edmx 文件作为 XML 文件打开
回答by cbeckner
If you want to keep the ProviderManifestToken
set to 2012, check the value for UseLegacyProvider
and make sure it is set to False.
如果要将设置保留ProviderManifestToken
为 2012,请检查 的值UseLegacyProvider
并确保将其设置为 False。