我在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的:恢复会话之后连接丢失
发布评论