“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.

, ,

  1. No comments yet.
(will not be published)
Submit Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word

Subscribe to comments feed
  1. No trackbacks yet.

SetPageWidth