Checking is SQL Service has started

  • Thread starter Thread starter Steven Blair
  • Start date Start date
S

Steven Blair

Hi,

Is it posssible to check if the SQL service is running. I have some code
accessing a SQL Database, but I get a nasty message if I forget to start SQL
Service.
 
If your code is running from the Server you can use the Process class to
verify that it's running. However, you may want to wrap the Connection.Open
in a Try/Catch block b/c this will fail if the service isn't running and
opening connections is a 'risky' operation.

HTH,

Bill
 
You can connect to sql server with socket and check if your server can accept incoming connections.

Here is code example:

Socket m_socClient = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
try
{
System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("SQL server IP Address");
System.Net.IPEndPoint remoteEP = new System.Net.IPEndPoint (ipAdd,1433);
m_socClient.Connect (remoteEP);
Console.WriteLine ("Your SQL is ronnung");
m_socClient.Close();
}
catch(SocketException se)
{
Console.WriteLine ("Your SQL seems not to be running");
}
 
You can connect to sql server with socket and check if your server can accept incoming connections

Here is code example

Socket m_socClient = new Socket(AddressFamily.InterNetwork,SocketType.Stream,ProtocolType.Tcp);
try

System.Net.IPAddress ipAdd = System.Net.IPAddress.Parse("SQL server IP Address")
System.Net.IPEndPoint remoteEP = new System.Net.IPEndPoint (ipAdd,1433)
m_socClient.Connect (remoteEP);
Console.WriteLine ("Your SQL is ronnung")
m_socClient.Close()

catch(SocketException se
{
Console.WriteLine ("Your SQL seems not to be running")
 
Back
Top