Can't run windows service
-
Hi, I've problem creating windows service, that can insert values into database using Sql-server 2000 and platform is ASP.NET 2.0 (C#), anyway I followed the whole code using from 'the code project' website; http://www.codeproject.com/cs/system/WindowsService.asp I write the whole code below again, and please let me know, what's wrong... Thanks. // WindowsService.cs using System; using System.Diagnostics; using System.ServiceProcess; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Configuration; namespace WindowsService { class WindowsService : ServiceBase { /// /// Public Constructor for WindowsService. /// - Put all of your Initialization code here. /// public WindowsService() { this.ServiceName = "My Windows Service"; this.EventLog.Source = "My Windows Service"; this.EventLog.Log = "Application"; // These Flags set whether or not to handle that specific // type of event. Set to true if you need it, false otherwise. this.CanHandlePowerEvent = true; this.CanHandleSessionChangeEvent = true; this.CanPauseAndContinue = true; this.CanShutdown = true; this.CanStop = true; if (!EventLog.SourceExists("My Windows Service")) EventLog.CreateEventSource("My Windows Service", "Application"); } /// /// The Main Thread: This is where your Service is Run. /// static void Main() { ServiceBase.Run(new WindowsService()); Test.ConnectionManager.Instance().Cb_Wap_NewItem(); // I addded this part from my } /// /// Dispose of objects that need it here. /// /// Whether or not disposing is going on. protected override void Dispose(bool disposing) { base.Dispose(disposing); } /// /// OnStart: Put startup code here /// - Start threads, get inital data, etc. /// /// protected override void OnStart(string[] args) {
-
Hi, I've problem creating windows service, that can insert values into database using Sql-server 2000 and platform is ASP.NET 2.0 (C#), anyway I followed the whole code using from 'the code project' website; http://www.codeproject.com/cs/system/WindowsService.asp I write the whole code below again, and please let me know, what's wrong... Thanks. // WindowsService.cs using System; using System.Diagnostics; using System.ServiceProcess; using System.Collections.Generic; using System.Collections; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; using System.Configuration; namespace WindowsService { class WindowsService : ServiceBase { /// /// Public Constructor for WindowsService. /// - Put all of your Initialization code here. /// public WindowsService() { this.ServiceName = "My Windows Service"; this.EventLog.Source = "My Windows Service"; this.EventLog.Log = "Application"; // These Flags set whether or not to handle that specific // type of event. Set to true if you need it, false otherwise. this.CanHandlePowerEvent = true; this.CanHandleSessionChangeEvent = true; this.CanPauseAndContinue = true; this.CanShutdown = true; this.CanStop = true; if (!EventLog.SourceExists("My Windows Service")) EventLog.CreateEventSource("My Windows Service", "Application"); } /// /// The Main Thread: This is where your Service is Run. /// static void Main() { ServiceBase.Run(new WindowsService()); Test.ConnectionManager.Instance().Cb_Wap_NewItem(); // I addded this part from my } /// /// Dispose of objects that need it here. /// /// Whether or not disposing is going on. protected override void Dispose(bool disposing) { base.Dispose(disposing); } /// /// OnStart: Put startup code here /// - Start threads, get inital data, etc. /// /// protected override void OnStart(string[] args) {
My experience with Windows services is that you have to login the service with a user account to use any network operations. So try to change this: //# Service Account Information serviceProcessInstaller.Account = ServiceAccount.LocalSystem; serviceProcessInstaller.Username = null; serviceProcessInstaller.Password = null; into: //# Service Account Information serviceProcessInstaller.Account = ServiceAccount.User; serviceProcessInstaller.Username = yourusername; serviceProcessInstaller.Password = yourpassword; With the correct values of course...
-------------------- Bertram Weckmann www.svizzer.com --------------------