Posts Tagged ‘windows service’

How to Debug Window Service without installing


Usually if we want to debug the windows service project to see if it is behaving as we expected, what we do is by installing the windows service and attaching that project to the process.

There is also another way to debug without installing it, what we need to do is by creating another project such as console project then copy and paste the code below.

  1.     Sub Main()
  2. #If Not Debug Then
  3.         Dim servicesToRun As System.ServiceProcess.ServiceBase()
  4.  
  5.         servicesToRun = New System.ServiceProcess.ServiceBase() {New MyService()}
  6.         System.ServiceProcess.ServiceBase.Run(servicesToRun)
  7. #Else
  8.         Dim service As AS2Client.AS2SenderService = New MyService()
  9.         service.myentrysub()
  10.  
  11.         System.Threading.Thread.Sleep(System.Threading.Timeout.Infinite)
  12.  
  13. #End If
  14.  
  15.  
  16.        
  17.     End Sub


References:
Run Windows Service as a Console program

Debugging Windows Services under Visual Studio .NET

, , ,

No Comments


An error occurred while validating. HRESULT = ’80004005′

An error occurred while validating. HRESULT = ’80004005′, this error just came up when I’m trying to organize my .Net Project files in my Solution, I removed some of the projects and just use the compiled dll in referencing to the main Project. However, this error has appeared during rebuilding the setup project and it took some of my time to find the solution or the cause.

So, what I did was I removed all References from the Target Primary Output project and added them and rebuilding it again , :) that’s it no more errors.


“Thank you for reporting this issue. We were able to reproduce the problem and have identified the root cause. The problem is caused by cross-solution project reference between Solution1 and Solution2. From the attached project, the project “WindowsFormApplication1” in Solution2 references a project that is not in Solution2 (it references ClassLibrary1 from Solution1). To fix the error, the workaround is to copy the ClassLibrary1 project to Solution2 and re-add the reference to ClassLibrary1 within its own solution.


Project-to-project references only works within the same solution. If you have to split into two solutions and split the code for your class library into two projects, you need to also split the project that references the class library into two projects (one for each solution) in order to avoid project references outside the current solution.

I hope this helps.

Candy Chiang
Program Manager – Visual Studio”

For more information and explanation about this error just click here

, , ,

No Comments


The [service name] service on local computer started and then stopped. Some Services stop automatically if they are not in use by another services or programs

Just check the event log viewer in order to see what was exactly happened.

More

No Comments


Mark for deletion Error when Installing Window Service

Problem
I got this error when I am trying to reinstall the Windows service after uninstallation. I did the following steps to re install the service.

a) I stopped the existing windows service using Administrative Tools –> Service
b) Keeping this Administrative tools –> Services window open, I tried to uninstall the service using InstallUtil.exe
c) I got the message “Service uninstallation successful”.
d) And then I tried installing the service again. It failed to install the service saying specified service has been marked for deletion.
Error message
An exception occurred during the Install phase. System.ComponentModel.Win32Exception: The specified service has been marked for deletion.
Cause
The registry entries related to the service are not deleted during the uninstallation. This error generally occurs when the service is uninstalled without stopping the existing service. However I got this error even when I uninstalled the service after stopping the service. This is because the Administrative Tools –>Services window is open when I was uninstalling the service. The registry entries are not deleted if the services window is kept open.
Solution
I found the following solution in newsgroups.

1. Stop the service
2. Close the Administrative Tools à Service window if it is open
3. Uninstall the service (only after closing the Administrative tools–> Services window. Opening the Services window during the uninstallation is the key reason why the above error is raised.)
4. Re Install the service again

Source: www.code101.com

,

1 Comment


How to Create Installer for Windows Service Project

To create a setup project for your service

  1. In Solution Explorer, right-click to select your solution, point to Add, and then click New Project.
  2. In the Project Types pane, select the Setup and Deployment Projects folder.
  3. In the Templates pane, select Setup Project. Name the project MyServiceSetup. Click OK.

    A setup project is added to the solution.

Next you will add the output from the Windows service project, MyNewService.exe, to the setup.

To add MyNewService.exe to the setup project

  1. In Solution Explorer, right-click MyServiceSetup, point to Add, then choose Project Output.

    The Add Project Output Group dialog box appears.

  2. MyNewService is selected in the Project box.
  3. From the list box, select Primary Output, and click OK.

    A project item for the primary output of MyNewService is added to the setup project.

Now add a custom action to install the MyNewService.exe file.

To add a custom action to the setup project

  1. In Solution Explorer, right-click the setup project, point to View, and then click Custom Actions.

    The Custom Actions editor appears.

  2. In the Custom Actions editor, right-click the Custom Actions node and choose Add Custom Action.

    The Select Item in Project dialog box appears.

  3. Double-click the Application Folder in the list box to open it, select Primary Output from MyNewService (Active), and click OK.

    The primary output is added to all four nodes of the custom actions — Install, Commit, Rollback, and Uninstall.

  4. In Solution Explorer, right-click the MyServiceSetup project and click Build.

, ,

No Comments


“Login failed error” when connecting to SQLServer From Windows Service

Your windows service is running under your LocalSystem account which obviously doesn’t have the correct privilidges to access the sql server. (DOMAIN\MachineName).

The reason this doesn’t happen in your winforms app is because this will be running under the user account you are logged into the machine as, which obviously does have the privilidges to access the sql server.

To grant your windows servce access rights to the sql server, you will need to set your service process installer to run under a user account, and define the credentials of a user who has access to the sql server,

Private Sub ProjectInstaller_BeforeInstall(ByVal sender As Object, ByVal e As System.Configuration.Install.InstallEventArgs) Handles Me.BeforeInstall
ServiceProcessInstaller1.Account = ServiceProcess.ServiceAccount.User
ServiceProcessInstaller1.Username = “Domain\account”
ServiceProcessInstaller1.Password = “password”
End Sub

or you can change the account type using service property from service.msc (administrative tools->Services) and locate the windows service you have created.

Properties->Log On Tab, select this account and browse.

, ,

No Comments


How to use Timer in Windows Service

You cannot use Timer Control in windows service it is because Timer Control is located at System.Windows.Forms.

Instead, use server timers from Timer namespace. To do this,

Friend WithEvents mTimer as New Timer.Timer

Protected Overrides Sub OnStart(ByVal args() As String)
mTimer.Interval = 6000 ’6 seconds

mTimer.Enable = true
End Sub
Private Sub mTimer_Elapsed(ByVal sender As Object, ByVal e As System.Timers.ElapsedEventArgs) Handles mTimer.Elapsed

‘Put your code here to execute
End Sub

, ,

No Comments



SetPageWidth