立即重新连接时出现 SQL 异常
我有一个使用 LinqToSql 的 winform 应用程序,因为它是 DAL。有一个中央 SQL DB,每台笔记本电脑都有一个本地 SQLExpress DB。一个单独的模块使用合并复制来保持两者同步。当与中央数据库的连接丢失时,它会“故障转移”到本地。这很好用。
但是,当我重新连接到中央数据库时,如果时间段不是很长,我会得到以下异常 -->
向服务器发送请求时发生传输级错误。 (提供程序:TCP 提供程序,错误:0 - 现有连接被远程主机强制关闭。)
我已经阅读了许多与此相关的SO 帖子,甚至这个 msdn 文章 概述并解释了,很详细,出了什么问题,通过这一切,我仍然没有找到或阅读解决方案。
我想知道其他人是如何处理这个问题的。我很难相信我正在踏入新的领域。有没有办法在重新连接时删除我的旧连接?
我为此失去了头发,所以任何见解都值得赞赏。
编辑
另外值得注意的是,我非常肯定我的所有数据上下文
都包装在using
中,并且我没有任何“长期” ' 上下文。
I have a winform app that uses LinqToSql as it's DAL. There is a Central SQL DB and each laptop has a local SQLExpress DB. A seperate module, using Merge Replication, keeps the two in sync. When connection is lost to the central DB it 'fails over' to the local. This works great.
However, when I regain conection to the central db, if the time period has not been real long, I get the following exception -->
A transport-level error has occurred when sending the request to the server. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)
I have read through numerous posts here on SO relating to this and even this msdn article that outlines and explains, in great detail, what is going wrong yet, through all of this, I have still not found or read a solution.
I am wondering how others have dealt with this. I find it hard to believe that I am treading new ground here. Is there a way to remove my old connections on reconnect?
I am losing hair over this so any insight is appreciated.
EDIT
Also of note, I am quite positive that all my Data Contexts
are wrapped in a using
and I do not have any 'long-term' contexts.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
使用“Pooling=false”连接字符串属性关闭连接池似乎已经解决了问题。
Turning off Connection Pooling using the "Pooling=false" connection string attribute seems to have solved the problem.