Access is denied when trying to start sql server using ServiceController RRS feed

  • Question

  • I have researched and researched this with no luck. I am looking to start a custom Instance "MSSQL$TRITON" of the MSSQL service. When I try to do this I get the following error:


    "Cannot open MSSQL$TRITON service on computer '.'." The inner exception is "Access is denied."


    My code is the following:


            if (Environment.MachineName == ConfigurationManager.AppSettings["DbMachineName"] ||
            ConfigurationManager.AppSettings["DbMachineName"] == "localhost")
              ServiceController service = new ServiceController(ConfigurationManager.AppSettings["SqlServiceName"]);
              if (service.Status != ServiceControllerStatus.Running)
                service.WaitForStatus(ServiceControllerStatus.Running, TimeSpan.FromSeconds(30));
          catch (Exception ex)
            success = false;

    Thanks in advance,


    • Moved by Leo Liu - MSFT Wednesday, May 4, 2011 5:43 AM Off Topic (From:Visual C# General)
    Wednesday, April 27, 2011 1:51 PM

All replies

  • hi,

    you have obviously not the permissions to start a service.

    Microsoft MVP Office Access
    Wednesday, April 27, 2011 1:57 PM
  • Hi Stefan Hoffmann:

    Are there any administrative privilege issues, I think we can do this if we have the permission.

    Md. Marufuzzaman
    Don't forget to click [Vote] / [Good Answer] on the post(s) that helped you.
    I will not say I have failed 1000 times; I will say that I have discovered 1000 ways that can cause failure – Thomas Edison.
    Wednesday, April 27, 2011 2:36 PM
  • The weird thing is I can start the service via : services.msc, it is just in the code that I can't.
    Wednesday, April 27, 2011 3:10 PM
  • Do you have User Account Control enabled? If so, typically you will need to elevate your process so it can perform administrative operations such as start/stop a service.

    You may need to elevate Visual Studio to run as an Administrator during debugging. For production applications, you should Create and Embed an Application Manifest and specifiy requireAdministrator, since accessing Windows Services needs that level of elevation in your application. Usually, if your application cannot run as an administrator then you will not be able to start/stop a Windows Service.


    Microsoft Community Contributor
    Thursday, April 28, 2011 4:19 AM
  • I am running Windows XP... I thought UAC was a Vista and Windows 7 deal
    Thursday, April 28, 2011 4:41 AM
  • Also just did another test. I am using WCF, and that code is from the Service that is installed on my machine. I tested the app by trying to

    start the service from the client side and it work perfectly! So it is just on the Service side that the problem occurs. Can anyone tell me why that is and how to fix it?

    Thursday, April 28, 2011 4:50 AM
  • your wcf service account must have permission to manage the windows service too. try making the account running the wcf service an administrator, for example.
    Microsoft Community Contributor
    Thursday, April 28, 2011 4:56 AM
  • How do I do this? I am fairly new with WCF...
    Friday, April 29, 2011 4:28 AM
  • Actually your issue is off-topic here in the current forum. If you could not get what you want, I'd like to suggest that you post your issue in the Windows Communication Foundation Forum for specialized support. Thanks.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Friday, April 29, 2011 5:26 AM