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:// ...
随机推荐
- SVN标准开发布局目录,trunk,branches,tags用法详解
http://www.cnblogs.com/newstar/archive/2011/01/04/svn.html 关于 SVN 目录结构 Subversion有一个很标准的目录结构,是 ...
- Android 小技巧-- TextView与EditText 同步显示
方法一.利用View.OnKeyListener"同步"显示 EditText myEdit = (EditText)findViewById(R.id.myEdit); Tex ...
- android 添加桌面快捷方式
.在桌面创建快捷方式方法: 方法一:通过长按某一个应用程序的图标在桌面上创建启动该应用程序的快捷方式. 这个方法安装完程序都用户都能实现. 方法二:在应用程序中构建一个Intent,然后以Broadc ...
- Android的各版本间的区别总结
Android 1.0 第一版商用操作系统 Android 1.1 更新了部分API,新增一些功能,修正了一些错误,同时增加com.google.android.maps包 Android 1.5智能 ...
- C#委托、事件剖析(下)
本节对事件进行总结. 二.事件: 1.概念:Event:A member that enables an object or class to provide notifications;官方的解释是 ...
- C# -- 等待异步操作执行完成的方式 C# -- 使用委托 delegate 执行异步操作 JavaScript -- 原型:prototype的使用 DBHelper类连接数据库 MVC View中获取action、controller、area名称、参数
C# -- 等待异步操作执行完成的方式 C# -- 等待异步操作执行完成的方式 1. 等待异步操作的完成,代码实现: class Program { static void Main(string[] ...
- Python学习笔记020——数据库中的数据类型
1 数值类型 数值类型分为有符号signed和无符号unsigned两种. 1.1 整型 int (1)bigint 极大整型(8个字节) 范围 :-2**64 ~ 2**64 - 1 -922337 ...
- ASP.NET Helper
- python标准库介绍——28 sha 模块详解
==sha 模块== ``sha`` 模块提供了计算信息摘要(密文)的另种方法, 如 [Example 2-39 #eg-2-39] 所示. 它与 ``md5`` 模块类似, 但生成的是 160 位签 ...
- ubuntu 12.04下gedit查看txt中文乱码解决办法
http://blog.sina.com.cn/s/blog_6273990801013dwv.html 由于我不能要求别人保存txt文件时必须用utf-8,那我只能自己找解决办法: 打开终端输入: ...