0

I understand how to check to see if a database exists on a SQL server on my local machine by using DbContext.Database.Exists(), but how do I check to see if the server is up and running?

I see a topic under "questions that may already have your answer" that recommends checking into the ServiceController class How can I verify if a Windows Service is running However, Visual Studio Intellisense does not detect System.ServiceProcess Namespace when I type it into my class.

Also, if the ServiceController class is the best answer to this question, how do i Identify to the ServiceController class what service it is that needs to be assigned to this object?

Community
  • 1
  • 1
ArmorCode
  • 719
  • 4
  • 14
  • 32

1 Answers1

1

Intellisense does not detect System.ServiceProcess Namespace when I type it into my class

Add a reference to the System.ServiceProcess.dll to your project.

I would refer to the MSDN documentation on how to use the ServiceController class. It's fairly easy to use.

pjwilliams
  • 190
  • 1
  • 9
  • The MSDN documentation says that when I initialize the ServiceController object, i should pass the name of the service to the constructor. But does this just initialize a new object with that name, or does the name you put in the string somehow look for the service with the corresponding name in the list of services? if so, Am I looking to put something like `ServiceController sc = new ServiceController("SQL Server");`? – ArmorCode Nov 17 '12 at 02:07
  • I found out how to do it. My service is named "SQL Server (SQLEXPRESS)" so i use that string. – ArmorCode Nov 17 '12 at 18:08