private static ISessionFactory Hbfactory; public static ISession OpenSession()
{
return GetHbFactory().OpenSession();
}
public static ISessionFactory GetHbFactory()
{
if (Hbfactory == null)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly(AssemblyName);
Hbfactory = cfg.BuildSessionFactory();
}
return Hbfactory;
}如果出现连接错误或者是资源没有释放,可否在这里断开然后重新连接呢?如果可以这样,请问怎么写
{
return GetHbFactory().OpenSession();
}
public static ISessionFactory GetHbFactory()
{
if (Hbfactory == null)
{
NHibernate.Cfg.Configuration cfg = new NHibernate.Cfg.Configuration();
cfg.AddAssembly(AssemblyName);
Hbfactory = cfg.BuildSessionFactory();
}
return Hbfactory;
}如果出现连接错误或者是资源没有释放,可否在这里断开然后重新连接呢?如果可以这样,请问怎么写
{
try{
return GetHbFactory().OpenSession();
}catch(exception ex)
{
return GetHbFactory().OpenSession();
}
}
在调用这个方法OpenSession的之后根据返回值,做下判断。。然后重新连接。
不过如果连接错误,可以继续尝试连接。
如果资源没有释放的话,继续尝试连接的时候,最好是能释放掉占用的资源,或者等资源空闲的时候再去连接。