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:// ...
随机推荐
- 常用ms-dos命令
netstat -ano 列出所有的活动链接netstat -ano|findstr 8080(也可以是pid号) 找到端口为8080的程序,例下图
- C# partial 关键字详解
我们新建一个Windows Form时,后台代码都会自动添加如下代码: public partial class Form1 : Form { public Form1() { InitializeC ...
- OGG_GoldenGate复杂参数定义(案例)
2014-03-10 Created By BaoXinjian
- AGPS定位基本机制
http://www.cnblogs.com/magicboy110/archive/2010/12/12/1903927.html 位置服务已经成为越来越热的一门技术,也将成为以后所有移动设备(智能 ...
- Spring Boot热部署(springloader)
使用方式一 在pom.xml文件添加依赖包: <plugin> <groupId>org.springframework.boot</groupId> <ar ...
- MongoDB查询指定字段(field)返回指定字段的方法
使用MongoDB的时候需要只查询指定的字段进行返回,也就是类似mysql里面的 SELECT id,name,age 这样而不是SELECT *.在MongoDB里面映射(projection)声明 ...
- unity 在脚本B中调用脚本A的函数
一,在脚本B中调用脚本A的函数. 脚本A: //myFuncs.cs using UnityEngine;using System.Collections; namespace myFuncs{ ...
- C 指向指针的指针
#include <stdio.h> int main() { char *cBooks[] = { "C程序设计语言", "C专家编程", &qu ...
- window 2008 定时任务调用bat不成功的解决方法
之前一直有在一台XP的机器上调用定时任务.如今这台机器换成了window 2008的操作系统,调用一直不成功.只是在偶然之间攻克了. 选择"任务计划程序" 任务计划程序库 ...
- C#操作txt文件并清空添加操作
C#操作txt文件,进行清空添加操作的例子.代码: //把txt清空 FileStream stream = File.Open(Adr,FileMode.OpenOrCreate,FileAcces ...