NHibernate的:恢复会话之后连接丢失 [英] NHibernate : recover session after connection lost

查看:247
本文介绍了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的不会处理连接断开你。对于偶尔连接的情况是这样我会考虑使用本地数据库在<一的建议href="http://stackoverflow.com/questions/134245/does-anyone-have-experience-creating-an-occasionally-connected-browser-app-with-n">this问题,然后使用 Microsoft同步框架以同步本地和中央数据库。另请参阅<一href="http://stackoverflow.com/questions/2387034/microsoft-sync-framework-clashes-with-nhibernate-toomanyrowsaffectedexception">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的:恢复会话之后连接丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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