Click here to Skip to main content
15,886,110 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all visitor
i created one application that connect to database(Sql server).but when the sql server service has been stop.my application still running.
My purpose is that when the sql stop service, My application should display a message to tell user about the connection. I want to know in VB.NET has any tools to watch my application when there is something wrong like i have mentioned above.

Best Regards,
Posted

You Create a thread which is use to check certain period your sql connection is alive or not. if not alive then you display message for user and take other action.
 
Share this answer
 
To add to what Rakesh said...

There is no tool that will do the monitoring for you.

You could run a background thread that will "ping" the server every so often. Basically, it would just try and open a connection to the database and run a very small query, then close it's connection. If this works, then the service is running. If not, well you've got your answer...

DO NOT OPEN A CONNECTION TO THE DATABASE AND KEEP IT OPEN FOR THE LIFE OF YOUR APPLICATION!

There may be someone who says that you need to use the Service Manager classes to check the state of the SQL Server service. The problem with this is that you need more than normal user permissions to do this and you would need to know the exact name of the SQL Server service instance. If you are running multiple instances of SQL on the same server, the name will change.
 
Share this answer
 
Comments
soeun tony 22-Jul-11 1:22am    
Thanks for your reply
You say "DO NOT OPEN A CONNECTION TO THE DATABASE AND KEEP IT OPEN FOR THE LIFE OF YOUR APPLICATION!"
I don't understand what you refer.
Could you explain me more?
Best Regards,
Dave Kreskowiak 22-Jul-11 7:35am    
Alot of newbies like to have their SqlConnection object class global, visible to every method in the class, maybe even passing it around like a $5 whore. They keep the connection object open for the entire time their application is running, only closing it when the application closes.

This is a very bad idea because connections licenses on SQL Server are expensive and hog resources on the server. You should be opening a connection, doing the query, then closing the connection.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900