Entity Framework优化一:引发了“System.Data.Entity.Core.EntityCommandExecutionException”类型的异常
错误信息:
“System.Data.Entity.Core.EntityCommandExecutionException”类型的异常在 EntityFramework.SqlServer.dll 中发生,但未在用户代码中进行处理。
其他信息:执行命令定义时出错。有关详细信息,请参阅内部异常。
跟踪代码找到详细信息:
Entity Framework已有打开的与此Command相关联的DataReader,必须首先将它关闭。
EF内部是使用DataReader作为资料存取,所以如果没关闭连接就会产生Error,因为DataReader用同一个Connection。
解决方案有两种:
1、在连接字符串上面加上MultipleActiveResultSets=true,允许多个链接操作。
<connectionStrings>
<add name="Default" connectionString="Server=.;Database=20171208;User ID=sa;Password=1qaz@WSX;MultipleActiveResultSets=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
2、在进行迭代的时候先取出放置在List中。
foreach (var photo in context.Photographs.ToList())
{
Console.WriteLine("图像:{0},缩略图{1}大小", photo.Title, photo.ThumbnailBite.Length); // 使用显示加载 把
context.Entry(photo).Reference(p => p.PhotographFullImage).Load();
Console.WriteLine("高分辨率图像:{0}大小", photo.PhotographFullImage.HighResolutionBits.Length);
}
Entity Framework优化一:引发了“System.Data.Entity.Core.EntityCommandExecutionException”类型的异常的更多相关文章
- Method 'ExecuteAsync' in type 'System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy' does not have an implementation
一.错误信息 Entity Framework 6.0数据迁移:Add-Migration XXXX 命令发生错误 System.Reflection.TargetInvocationExceptio ...
- ef添加数据时出错 System.Data.Entity.Infrastructure.DbUpdateConcurrencyException”类型的异常
找半天才找到 ef添加数据时出错原因:数据库表中没有主键 ,就算表中有自增列 Added方法也会报错: - this._db.SaveChanges() “this._db.SaveCh ...
- System.Security.SecurityException The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception
[15/08/19 00:03:10] [DataManager-7292-ERROR] System.Reflection.TargetInvocationException: Exception ...
- The Entity Framework provider type 'System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer' registered in the application config file for the ADO.NET provider with invariant name
可以强迫部署EntityFramework.SqlServer.dll这个文件到输出目录 找到1个老外的帖子,戳这里(本人测试无效,大家有可能试一下..) 解决方案以下: 在EF的上下文代码CS文件( ...
- “System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常。{转}
<connectionStrings> <add name="ConnectionStringName" providerName="System.Da ...
- System.Data.Entity.Internal.AppConfig 类型初始值设定项引发异常
在一开始时将connectionStrings 写在了configSections之上如下图一示,结果抛出:“System.Data.Entity.Internal.AppConfig”的类型初始值设 ...
- 使用EF访问数据库,出现“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。
今天在使用的EF时候,发生了"System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常.这样的一个错误 查了原因,原来是appconf ...
- System.Data.Entity.Internal.AppConfig"的类型初始值设定项引发异常
在学习EF code First的小案例的时候,遇见了这个异常 <configSections> <!-- For more information on Entity Framew ...
- Entityframework:“System.Data.Entity.Internal.AppConfig”的类型初始值设定项引发异常。
<configSections> <!-- For more information on Entity Framework configuration, visit http:// ...
随机推荐
- Android应用程序结构总结
Android应用程序结构分析 由于是初学者,对于Android应用程序的结构的认识是一穷二白的,对于开发Android应用程序,必须先了解其程序的结构和作用.一下就用一个简单的例子来解剖: 从上图的 ...
- Android学习系列(12)--App列表之拖拽GridView
根据前面文章中ListView拖拽的实现原理,我们也是很容易实现推拽GridView的,下面我就以相同步骤实现基本的GridView拖拽效果. 因为GridView不用做分组处理,代码处理起来 ...
- ASP.NET中UrlEncode应该用Uri.EscapeDataString()
今天,茄子_2008反馈他博客中的“C++”标签失效.检查了一下代码,生成链接时用的是HttpUtility.UrlEncode(url),从链接地址获取标签时用的是HttpUtility.UrlDe ...
- iOS设备的标识---UUID和IDFA
一:1.1 :UDID 简介:UDID的全称是Unique Device Identifier,顾名思义,它就是苹果IOS设备的唯一识别码,它由40个字符的字母和数字组成.在很多需要限制一台设备一个账 ...
- oc 调用c语言方法和oc的方法调用
//c语方的方法 void sayHello(){ printf("Hello OC"); } int main(int argc, char * argv[]) { sayHel ...
- 管道读写规则和Pipe Capacity、PIPE_BUF
一.当没有数据可读时 O_NONBLOCK disable:read调用阻塞,即进程暂停执行,一直等到有数据来到为止. O_NONBLOCK enable:read调用返回-1,errno值为EAGA ...
- __attribute__中constructor和destructor
1.前言 最近看到一份代码,看到一个函数前面用__attribute__((destructor))修饰,当时感觉有点怪怪的,搜了整个程序,也没发现哪个地方调用这个函数.于是从字面意思猜想,该函数会在 ...
- Google Guice之作用域
默认情况下,Guice获取一个实例时.每次都会返回一个新的对象. 这个行为能够通过scopes进行配置.Scopes同意你复用实例: 应用整个生命周期(@Singleton),会话(@Session) ...
- CXF+Spring+JAXB+Json构建Restful服务
话不多说,先看详细的样例: 文件文件夹结构: web.xml <?xml version="1.0" encoding="UTF-8"? > < ...
- SIPp常用脚本之三:UAC
UAC是作为SIP消息的发起端,可以控制消息速率什么的,方便极了. 一.uac.xml <?xml version="1.0" encoding="ISO-8859 ...