C# windows service connect to sql server


















Connection between windows service and sql database Ask Question. Asked 10 years, 3 months ago. Active 10 years, 3 months ago. Viewed 5k times. I have used same connection for both windows service and console application.

Improve this question. Under which credentials runs your service? If you manually set your service to run as your user, do this solve your problem?

Add a comment. Active Oldest Votes. Improve this answer. Marco Marco So you can simulate you're running console app I mean, to run your console app probably you were logged as a particular user: user that user with related pwd to run your service and see if your problem raises again or not Sign up or log in Sign up using Google.

Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. This of course bring the issue of configuring such an account, with regards to the privileges it should be granted, at the level of the system not of SQL , and depending on what the underlying Service does, on may need to make this account rather powerful, hence a potential liability in other ways When a Windows Service is started by the Service Control Manager, the process executes as a particular user just as with any other process running on the OS.

There are a number of "built-in" user accounts that are used for running Windows Services. You can see the complete set of Windows Services and the account they run as called "Log On As" in Windows 7 if you look at the "Services" node within Computer Management". From my experience, when we want a Windows Service to talk to the DB using integrated security we take the second approach below:. It is possible thru the installer to prompt for the user account credentials during the installation of the service.

I can't claim to be expert enough to point out all pros and cons of each approach, however it's worth considering the following:. This is not the case with approach 2. If you want to use trusted windows authentication, the easiest thing to do is to run the service with a domain account with the least privilleges required that is permissioned to the sql server database.

As mjv said, you need to either give Local Service Account access to the database or use a different account to run the service. You asked how you can change the account programmatically, which is accomplished by creating an Installer for the service and changing the Account property to "User" then specifying the Username and Password to run the service.

How are we doing? Please help us improve Stack Overflow. Take our short survey. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Collectives on Stack Overflow. Learn more. How to connect to sql-server with windows authentication from windows-service? Ask Question.

Asked 11 years, 11 months ago. Active 1 month ago. Viewed 25k times. However that doesn't work as I get a: System. Add Comment. Login or Register to comment. Related Articles NET Core. Using Generics in C With Example. Related Questions Cannot convert null to a value type JSON error. DbArithmeticExpression arguments must have a numeric common type.

The name of the connection string. Maps to the name attribute. The fully qualified provider name. Maps to the providerName attribute.



0コメント

  • 1000 / 1000