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:// ...
随机推荐
- Total Commander:文件管理工具,共享软件
http://xbeta.info/tc/ Total Commander V8.0:文件管理工具,共享软件,适用于Windows® 95/98/ME/NT/2000/XP/Vista/7 和 Win ...
- MongoDB Windows环境安装及配置[转]
MongoDB一般安装 1.首先到官网(http://www.mongodb.org/downloads )下载合适的安装包,目前的最新版本为2.6 安装包有zip和msi格式的,这里推荐下载zip格 ...
- vs开发 winform 设置winform 获取管理员权限启动
因为需要设置为开机项 没有管理员权限对注册表访问失败 C# 以管理员身份运行WinForm程序 转载https://www.bbsmax.com/A/obzbkKrQJE/ 鱼洛 2016-07-29 ...
- 【转载】Gradle构建多模块项目
本文转载自:https://yq.aliyun.com/articles/25589写的非常好! 改动如下: 1. 增加了一些[补充说明]. 2. 将执行命令使用较为显眼的博客园样式. 3. 将输出结 ...
- Centos网络配置小工具
之前在CentOS 6下编辑网卡,直接使用setup工具就可以了. 但在新版的CentOS 7里,setuptool已经没有网络编辑组件了,取而代之的是NetworkManager Text User ...
- Spring mvc中DispatcherServlet详解
简介 DispatcherServlet是前端控制器设计模式的实现,提供SpringWebMVC的集中访问点,而且负责职责的分派,而且与spring IOC容器无缝集成,从而可以获得Spring的优势 ...
- 每日英语:China Poses Challenge for Coal
China's appetite for coal, once seemingly unlimited, is starting to wane, and the effects are rippli ...
- 每日英语:Does Evolution Want Us To Be Unhappy?
Samuel Johnson called it the vanity of human wishes, and Buddhists talk about the endless cycle of d ...
- ny8 一种排序 sort
一种排序 时间限制:3000 ms | 内存限制:65535 KB 难度:3 描述 现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复:还知道这个长方形的宽和长,编号.长.宽都是整数:现 ...
- flask celery 使用方法
一.安装 由于celery4.0不支持window,如果在window上安装celery4.0将会出现下面的错误flask_clery 你现在只能安装pip install celery==3.1 二 ...