Windows service start error: cannot start service from command line or debugger

Hi i get this error

Cannot start service from command line or debugger. Winwows must first be installed (using installutil.exe) and then started with ServerExplorer, the Windows Services mid-level administrator, or the NET START command.

and I don’t understand why I get this error. And here is my code:

{ string Hash = ""; string connectionstring = ConfigurationManager.ConnectionStrings["myConnectionString"].ConnectionString; SqlConnection myConnection = new SqlConnection(connectionstring); SqlCommand myCommand = new SqlCommand("GetNullHash", myConnection); myCommand.CommandType = CommandType.StoredProcedure; myConnection.Open(); SqlDataReader rdr = myCommand.ExecuteReader(); while (rdr.Read()) { string filename = @"\\" + rdr.GetString(3); filename = System.IO.Path.Combine(filename, rdr.GetString(2)); filename = System.IO.Path.Combine(filename, rdr.GetString(1)); Hash = rdr.GetString(0); Hash = computeHash(filename); } myConnection.Close(); return Hash; } 
+42
c # windows-services
Jul 20 2018-12-12T00:
source share
6 answers

Watch this video , I had the same question. It also shows you how to debug a service.

Here are his instructions using the basic Windows C # service template in Visual Studio 2010/2012.

You add this to the Service1.cs file:

 public void onDebug() { OnStart(null); } 

You change your Main () to call your service this way if you are in the Active Solution DEBUG configuration.

 static void Main() { #if DEBUG //While debugging this section is used. Service1 myService = new Service1(); myService.onDebug(); System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite); #else //In Release this section is used. This is the "normal" way. ServiceBase[] ServicesToRun; ServicesToRun = new ServiceBase[] { new Service1() }; ServiceBase.Run(ServicesToRun); #endif } 

Keep in mind that for now this is a great way to debug your service. It does not call OnStop() unless you explicitly call it similar to the way we called OnStart(null) in the onDebug() function.

+50
Jun 24 '13 at 2:14
source share
β€” -

To install the service manually

To install or uninstall the Windows service manually (which was created using the .NET Framework), use the InstallUtil.exe utility. This tool can be found on the following path (use the appropriate wireframe version number).

C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe

For installation

 installutil yourproject.exe 

To delete

 installutil /u yourproject.exe 

See: How to install and remove services (msdn)

Install service programmatically

To programmatically install a service using C #, see the following ServiceInstaller class (c-sharpcorner).

+25
Jul 20 '12 at 6:11
source share

Your code has nothing to do with installing the service, this is not a problem.

To check the service, you must install it as indicated.

Additional Service Installation Information: Add or Remove Services

0
Jul 20 '12 at 6:11
source share

I suggest creating an installation project for reasons, while deploying it seems to be the best convenience, without the headaches of manually copying files. Follow the tutorial on creating a Windows installation and you know how to create it. And this instance is for vb.net, but it is the same for any type.

0
Jul 20 '12 at 6:17
source share

To install Open CMD and enter {YourServiceName} -i after its installed type in NET START {YourserviceName} to start the service

for removing

To remove Open CMD and enter NET STOP {YourserviceName} once stopped type in {YourServiceName} -u , and it should be deleted

0
Jul 20 '12 at 6:18
source share

Go to App.config

Find

 <setting name="RunAsWindowsService" serializeAs="String"> <value>True</value> </setting> 

Set to False

-one
Dec 26 '14 at 4:01
source share



All Articles