Click here to Skip to main content
15,881,715 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a WPF application and on a Timer (30 seconds) I want to check if the database server is still ONLINE. My application shows an image t see if it is online or not (red light/green light).
I can create a ADO.NET connection (via connectionstring) and open and close a connection.

Is there a way to check in c#/WPF if the database is online without opening and closing a connection each time?

Regards,

Herman
Posted
Comments
ZurdoDev 5-Mar-15 8:26am    
Without opening and closing a connection each time? I doubt it. You would have to connect to be able to check status anyway.
[no name] 5-Mar-15 8:47am    
Since you didn't get a solution yet, I'll tell you my non-expert thoughts: Depending on the type of database server you're using there might be some API function for that purpose. But I don't think your current solution is bad - opening and closing a connection once every 30 seconds isn't something to worry about.
John C Rayan 5-Mar-15 9:00am    
Can you explain why you would want to do that? Without checking beforehand you can go on about connecting and do the query. If the DB doesn't exist then you will get an exception. Catch the exception and report it.
Herman<T>.Instance 5-Mar-15 9:08am    
It is just for visual purposes so the user can see in the statusbar of the form if the database is on green light of red light. It is just information, no more.

1 solution

It is possible using
C#
System.Data.Sql.SqlDataSourceEnumerator 



Example found here[^].
 
Share this answer
 
Comments
[no name] 5-Mar-15 9:57am    
It's not universally reliable, see
http://stackoverflow.com/questions/13984920/how-can-i-use-system-data-sql-sqldatasourceenumerator-class-to-know-available-sq
http://stackoverflow.com/questions/6824188/sqldatasourceenumerator-instance-getdatasources-does-not-locate-local-sql-serv?lq=1
Herman<T>.Instance 5-Mar-15 10:34am    
thanx for your information.

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