Click here to Skip to main content
15,890,825 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
any time checking sql connection and database available or not from windows service.
if not available send parameter to windows forms texts


What I have tried:

iam a beginner in c# give some ideas or example.
Posted
Updated 15-Apr-20 10:07am

You don't. Services should never try to contact applications to tell them something. The applications may not be running or you may have multiple copies of them running.

Your applications could, on the other hand, contact the service.

But, your service seems to be pointless as applications are always written to detect and handle database server not responding themselves. They don't need a service to tell them this.

Also, the service will only check once in a while, not continuously. So, When the service runs its pass and detects that the database is up, a couple of seconds later, or even the next millisecond!, the server may stop responding, even though your applications have been told that it is responding according to the service.
 
Share this answer
 
Comments
gowthamanpakt 18-Apr-20 2:38am    
thanks for your comments...
Here is a quick outline for you
C#
// declare SqlConnection, SqlCommand

try {
  // define SqlConnection
  // define SqlCommand
  // open connection
  // execute command
  // close connection
}
catch (SqlException sx) {
 // handle appropriately
 // send notification of sx
}
catch (Exce[tion ex) {
  // handle the other error as needed
}
finally {
 // dispose of SqlCommand, SqlConnection
}
f
 
Share this answer
 
Comments
gowthamanpakt 18-Apr-20 2:38am    
thanks for your comments...

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