与远程 SQL 服务器断开连接后 EF 4.0 中的错误?
我发现在 Web 服务器与远程 sql 服务器断开连接并重新连接后,EF 4.0 会抛出异常“现有连接被远程主机强制关闭”。 例如,我编写以下代码:
using (SparePartEntities aa = new SparePartEntities())
{
var bb = aa.TS_SYS_User.ToArray();
}
首先,我在网页中运行代码,结果是好的。
然后我断开网络连接并重新连接。
当我刷新 asp.net 页面时,会抛出异常“现有连接被远程主机强制关闭”。
我发现在 EF 1.0 中应该可以吗?怎么了?
I find the EF 4.0 would throw an exception "An existing connection was forcibly closed by the remote host" after the web server disconnected from remote sql server and re-connect with it.
for example,I write the below code:
using (SparePartEntities aa = new SparePartEntities())
{
var bb = aa.TS_SYS_User.ToArray();
}
firstly, i run the code in web page and the result is ok.
Then I disconnect the network connection and reconnect it.
When i refresh the asp.net page, an exception would be thrown "An existing connection was forcibly closed by the remote host".
I find it would be OK in EF 1.0? What's wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不是 EF 中的错误。这是使用连接池时众所周知的行为。问题是连接池保存打开的连接,这些连接将被重用于后续的数据库访问。但如果您断开网络连接,这些连接就会出现故障。下次使用该连接将引发上述异常。
That is not a bug in EF. That is well known behavior when using connection pooling. The problem is that connection pool holds opened connections which are reused for subsequent database access. But if you disconnect from the network these connections will be faulted. Next usage of that connections will throw the mentioned exception.