NHibernate的:恢复会话之后连接丢失

编程入门 行业动态 更新时间:2024-10-27 03:36:27
本文介绍了NHibernate的:恢复会话之后连接丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我在WPF客户端应用程序使用NHibernate与SQL Server 2005。

I'm using NHibernate with SQL Server 2005 in a WPF client application.

如果我手动停止SQL Server服务,然后重新启动会话不会自动重新连接。

If I manually stop the SQL Server service and then restart it the session doesn't automatically reconnect.

到目前为止,我这样做魔女似乎工作:

So far I'm doing this witch seems to work :

try { using (ITransaction transaction = this.Session.BeginTransaction()) { // some select here } }catch(Exception ex) { if(this.Session.Connection.State == ConnectionState.Closed) { try { this.Session.Connection.Open(); } catch (Exception) { } } }

有没有更好的办法?

Is there a better way ?

推荐答案

NHibernate的不会处理连接断开你。对于偶尔连接的情况是这样我会考虑使用本地数据库在this问题,然后使用 Microsoft同步框架以同步本地和中央数据库。另请参阅this相关的问题。

NHibernate won't handle connection drops for you. For occasionally connected scenarios like this I'd look into using a local database as suggested in this question, and then use the Microsoft Sync Framework to synchronize the local and central databases. Also see this related question.

更多推荐

NHibernate的:恢复会话之后连接丢失

本文发布于:2023-10-11 22:19:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1483002.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:NHibernate

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!