hi i'm getting this error
Cannot start service from the command line or debugger. A winwows Service must first be installed(using installutil.exe) and then started with the ServerExplorer, Windows Services Afministrative tool or the NET START command.
and i dont understand why im geting 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; }
"Cannot start service from command line or debugger. A windows service must first be installed using installutil.exe and then started with service explorer, Windows services administrative tool or NET start..
A Windows Services Must First be Installed(Using InstallUtil.exe) and then started with the ServerExplorer,Windows Services Administrator Tool or the NET START command.
In the Application tab of the project's properties, set the Output type to Console Application. Choose Start Debugging (F5). To run the program as a Windows Service again, install it and start it as usual for a Windows Service.
Watch this video, I had the same question. He shows you how to debug the service as well.
Here are his instructions using the basic C# Windows 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 DEBUG Active Solution 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 while this is an awesome way to debug your service. It doesn't call OnStop()
unless you explicitly call it similar to the way we called OnStart(null)
in the onDebug()
function.
To install your service manually
To install or uninstall windows service manually (which was created using .NET Framework) use utility InstallUtil.exe
. This tool can be found in the following path (use appropriate framework version number).
C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\InstallUtil.exe
To install
installutil yourproject.exe
To uninstall
installutil /u yourproject.exe
See: How to: Install and Uninstall Services (Microsoft)
Install service programmatically
To install service programmatically using C# see the following class ServiceInstaller (c-sharpcorner).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With