I would approach it this way. 1. determine if connection can be opened? 2. open session (from this point forward assume a good connection) 3. do work 4. dispose session
if the connection drops, let the exception bubble up to the application layer. at this point catch the specific exception which indicates the connection dropped and start the whole process over again at a future point in time (anywhere from 1 second to whenever) this gives infrastructure time to "reset" so you can make the connection. On Oct 8, 6:43 pm, Waqar Sadiq <[email protected]> wrote: > We are using NHibernate 2.1 along with Spring.net. All transactions > are being declaratively managed by Spring. Majority of the database > interaction is ofcourse queries being executed. The underlying > database is Oracle 10g. because of various reasons, the underlying > socket connections are being terminated by the firewall. What I need > to do is to figure out how to detect that situation, re-establish the > session and then re-execute a query. I am actually interested in only > doing this for queries. > > My test case is a web application that I start and it executes soem > queries to open conenctions. I then manually kill the conenction to > simulate the scenario. > > We have a base object that all the data access objects derive from. > The base class has a "Session" property that gets the current > session. Below is the code for this property. > > public ISession CurrentSession > { > get > { > ISession session = null; > try > { > session = HibernateTemplate.SessionFactory.GetCurrentSession(); > } > catch (HibernateException) > { > session = DoGetSession(true); > } > catch (Exception ex) > { > _logger.Error(_className, "CurrentSession", "Error > getting a valid session", ex); > throw; > } > System.Data.ConnectionState state = session.Connection.State; > _logger.Debug(_className, "CurrentSession", "Connection state = " > + Enum.GetName(typeof(System.Data.ConnectionState), state)); > return session; > } > > } > > After I kill my session, the line above that check the state of the > conenction still shows it to be open. > > I have centralized the execution of the criteria to the following > method. > > protected IList<T> ExecuteCriteria<T>(ICriteria criteria) > { > IList<T> set = null; > int tries = 0; > while (tries < MaxTriesToRecover) > { > try > { > set = criteria.List<T>(); > return set; > } > catch (Exception ex) > { > tries++; > if (tries >= MaxTriesToRecover) > { > throw HandleException(string.Empty, ex); > } > else > { > // try to re-establish the session. CAN ANYBODY HELP > HERE. > } > } > } > return set; > > } > > I would really appreciate some help in how can I re-establish > conenction in the above method and seamlessly re-execute the criteria? > > Thanks in advance. > > Waqar --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
