views:

624

answers:

2

A WCF service is hosted in a Windows Service (WS).

When the database (SqlServer 2005) goes down a SqlException is thrown due to the actions performed on the database.

What I want to accomplish is that the WS - where the WCF service is hosted - should go down when the DB is also down.

The WS will be restarted manually by the way.

My idea is to do nothing about it. The unhandled exception will stop the WS.

Is this the correct way to do ?

+1  A: 

First of all you need to detect that SQL server went down from the SQLException you will get. Secondly why to kill the webservice instead return an error to client saying service is down temporarily for so and so reason.

Bhushan
The second point: the customer want it that way, no discussion, pffff
Patrick Peters
That's pretty stupid... So when the DB is back up they have to manually restart it?
Rob Stevenson-Leggett
@Rob: yes, that's what they do...
Patrick Peters
+2  A: 

If you want to explicitly stop your windows service, just call the .Stop() method on your service class.

Windows services can be configured to automatically restart on error - so just letting the SqlException flow to the top might not achieve what you want.

Marc

marc_s
The 1st scenario you show will force my to catch on the SqlException and then stop the windows service itself.The 2nd scenario is little confusing for me: if I configure my WS to restart on error, then bubbling the SqlException will restart the WS, so that would be the solution.
Patrick Peters
1st scenario: I thought that's what you asked for - no? 2nd scenario: this is a feature of the standard Windows Service Controller - you can specify what to do on the first, second and third failure of a service - restart being just one of the options.
marc_s