该命令的执行需要一个开放和可用的连接。该连接的当前状态被打破。 [英] Execution of the command requires an open and available connection. The connection's current state is broken.

查看:154
本文介绍了该命令的执行需要一个开放和可用的连接。该连接的当前状态被打破。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在QA中的一些使用,我们得到以下错误

命令的执行需要一个开放和可用的连接。该连接的当前状态被打破了。

我们正在使用的EntityFramework的单一实例

SOF提示:

<一个href=\"http://stackoverflow.com/questions/2863224/ef-recovery-from-invalidoperationexception-caused-by-server-being-down\">EF从InvalidOperationException异常复苏造成服务器关闭

1)一次的同时创建ContectObject的新实例

2)配置池连接的数量要高

什么是解决这个问题的最佳做法?

我认为这是wastefull来为每个德尔操作的新contectObject


解决方案

  

我认为这是wastefull来为每个德尔操作的新contectObject


你有没有这方面的任何证据?我相信,实体框架和最确实的数据访问框架是的设计的为许多短命的,独立的环境。在这里实现自己的池/缓存通常是一个反模式,可能导致陈旧的结果,并发问题和故障恢复不好(比如这里的情况)。

什么具体的资源,你觉得会被浪费,并有你验证了该实验?

基本上,我会建议创建工作的各单位新环境(可能大致对应一个请求) - 衡量任何性能的差异,看看问题是否消失(因为我希望它会)。作为测试的一部分,偶尔会从网络上断开数据库服务器来检查,你实际上可以恢复,太...

After some use in qa we get the following error

Execution of the command requires an open and available connection. The connection's current state is broken.

We’re using a singleton instance of EntityFramework

SOF suggests :

EF recovery from invalidoperationexception caused by server being down

1) creating a new instance of ContectObject once in a while

2) configure the number of pool connections to be higher

What is the best practice to solve this?

I think it's wastefull to create a new contectObject for each Dal operation

解决方案

I think it's wastefull to create a new contectObject for each Dal operation

Do you have any evidence for this? I believe that Entity Framework and indeed most data access frameworks are designed for lots of short-lived and independent contexts. Implementing your own pooling / caching here is usually an anti-pattern, possibly resulting in stale results, concurrency issues, and poor failure recovery (as is the case here).

What specific resources do you think will be wasted, and have you validated this experimentally?

Basically, I would suggest creating a fresh context for each unit of work (may well correspond roughly to a request) - measure any performance differences, and see whether the problem goes away (as I expect it will). As part of your testing, occasionally disconnect the database server from the network to check that you can actually recover, too...

这篇关于该命令的执行需要一个开放和可用的连接。该连接的当前状态被打破。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆