问题描述
我有一个简单的.NET应用程序(MS Visual Studio 2013,.NET 4.5.1 EF 6.1.1)。
I hav e a simple .NET Application (MS Visual Studio 2013, .NET 4.5.1 EF 6.1.1).
当我想访问数据库时,出现以下错误:
When I want to access the database, I get following error:
mscorlib.dll中出现未处理的"System.InvalidOperationException"类型异常
An unhandled exception of type 'System.InvalidOperationException' occurred in mscorlib.dll
附加信息:实体框架提供程序类型'System.Data.Entity.SqlServer.SqlProviderServices,EntityFramework.SqlServer'在应用程序配置文件中注册无法加载具有
不变名称'System.Data.SqlClient'的ADO.NET提供程序。确保使用了程序集限定名称,并且程序集可供正在运行的应用程序使用。有关详细信息,请参阅http://go.microsoft.com/fwlink/?LinkId=260882。
错误发生在(AdresModel.Context.cs)
namespace adressen
{
using System;
using System.Data.Entity;
using System.Data.Entity.Infrastructure;
using System.Data.SqlClient;
public partial class AdressenEntities: DbContext
{
public AdressenEntities()
: base("name=AdressenEntities") <------error
{
}
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
throw new UnintentionalCodeFirstException();
}
public virtual DbSet<Adres> Adres { get; set; }
}
}
我的App.Config如下:
My App.Config is as follows:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
</configSections>
<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="AdressenEntities" connectionString="metadata=res://*/AdresModel.csdl|res://*/AdresModel.ssdl|res://*/AdresModel.msl;provider=System.Data.SqlClient;provider connection string="data source=localhost\sqlexpress;initial catalog=Adressen;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
</configuration>
我在互联网上发现其他人也遇到此问题,但是到目前为止还没有解决方案。
I found on the internet that also other people had a problem with this, but so far no solution.
感谢您的帮助。
Willem
推荐答案
这篇关于MS VS 2013 EF6.1.1 mscorlib.dll中发生未处理的“System.InvalidOperationException”类型异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!