-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: SQL Server Connection
PostPosted: Mon Dec 10, 2007 7:59 am 
Newbie

Joined: Wed Nov 21, 2007 1:47 pm
Posts: 6
Hibernate version:1.2.0.3001
Name and version of the database you are using:SQL Server 2005

Once again I will try to ask this forum about a connection issue between OpenSession and session.close(). And how to reconnect when this happends.

I have a application that are selecting, updating and deleting rows in some database tables.

My trouble is that the Database server is not on the same computer that my application is running on and sometimes I loose connection to this server.

When this happens, I will get an error on some of the object. But since I use the lazy model (i think), the exception does not come right away. I am able to select from my tables (that are selected from before) regardless of the connection state. But I cant update when the connection is down, and that is correct.

I want to know right away when I loose the connection to the database.
How can I do this?

Do anyone have a nice solution for monitoring the connection state to a database server?

Regards
Svein Thomas


Top
 Profile  
 
 Post subject: Re: SQL Server Connection
PostPosted: Mon Dec 10, 2007 10:37 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Svein Thomas wrote:
Hibernate version:1.2.0.3001
Name and version of the database you are using:SQL Server 2005

Once again I will try to ask this forum about a connection issue between OpenSession and session.close(). And how to reconnect when this happends.

I have a application that are selecting, updating and deleting rows in some database tables.

My trouble is that the Database server is not on the same computer that my application is running on and sometimes I loose connection to this server.

When this happens, I will get an error on some of the object. But since I use the lazy model (i think), the exception does not come right away. I am able to select from my tables (that are selected from before) regardless of the connection state. But I cant update when the connection is down, and that is correct.

I want to know right away when I loose the connection to the database.
How can I do this?

Do anyone have a nice solution for monitoring the connection state to a database server?

Regards
Svein Thomas


I don't believe you are looking at the problem from the right angel since I don't understand why you need to know when a connection is dropped. You won't be able to resume with a new connection in many cases and even if you do you will have to solve transaction problems. You will have to design your code so that database failures are tolerated. I do recommend that you slice up your units of work into smaller pieces and put them in a JMS queue so that they can be retried. You may also consider doing read only parts and write only parts even though in many cases this distinction is impossible.


Farzad-


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 3:16 am 
Newbie

Joined: Wed Nov 21, 2007 1:47 pm
Posts: 6
Thanks for the answer.
What is a JMS queue?

My code is like this (in words):
- Get some data from some tables in database A
- Write the retrieved data to a table in database B
- Update some tables in database A


Everything is done in transactions. So when something fails, nothing get written to the databases.

I took a copy of the Basic Example from the Best Practices page at www.codeproject.com (http://www.codeproject.com/KB/architect ... tices.aspx)

Should I add some exception handling in the NHibernateSessionManager.GetSession? Or some other place? What is your suggestion?

Regards
Svein Thomas


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 12:15 pm 
Expert
Expert

Joined: Wed Apr 11, 2007 11:39 am
Posts: 735
Location: Montreal, QC
Svein Thomas wrote:
Should I add some exception handling in the NHibernateSessionManager.GetSession? Or some other place? What is your suggestion?

Regards
Svein Thomas



Ah, my bad again. This is the second time I don't realize I am writing in a NHibernate forum. What I said makes sense in Java. However, .Net might also have a solution for this. Your problem here is even bigger since you will need to use distributed transactions as you are updating multiple sources. As per my understanding, you can not resume whatever you have been doing on a connection on another connection. You will need to restart the whole thing unless you can split each step in a retriable unit of work in whatever .Net's message system is. Successful end of each step triggers the next step which will be done in a new transaction scope and with a new connection/session. The point behind using messaging systemd is that it treats each message as unit of work which should complete and it can be configured to retry if a unit fails. However, this might not be the choice for you if timing is an issue since messaging systems are very useful where asynchronous communications are applicable.


Farzad-


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.