Click here to Skip to main content
15,886,026 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
Hello,

My Windows Service can't access to a local SQL database, I have no idea what is the problem, it connects well in console app with the same connection string.
My connectionString is
"Data Source=localhost;Initial Catalog=comp;Integrated Security=True";

("comp" is my database name)
My windows service is a Local System account.

Thanks for your answer!

Zoli
Posted
Updated 29-Oct-13 4:53am
v3
Comments
ZurdoDev 29-Oct-13 10:34am    
We need the error; however, it is likely that whatever account your service is running as does not have a sql login.
borzola7 29-Oct-13 10:55am    
I am beginner so apologize me. How do you make sql login? If I start SQL Server Management Studio I always connect to localhost (servername), I don't know other way.
How do you connect your database to be accessable for window service with a connectorString like this: "server=ABC\\SQLEXPRESS; database=db1; uid=sa; password=sa" (I have seen it in a windows service example)
ZurdoDev 29-Oct-13 11:08am    
You can add a new User under Security in Sql Management Studio or you can use Windows Authentication but then the account your service is running as needs a login.
borzola7 29-Oct-13 13:27pm    
In the event log the service gives this error message: System.Data.SqlClient.SqlException (0x80131904): "The service can't start. The SELECT permission was denied on the object 'Company', database 'comp', schema 'dbo'."
ZurdoDev 29-Oct-13 13:41pm    
Yes, permissions issue. Get with your db admin to fix it.

1 solution

Thank you guys! You were really helpful! SQL authentication connection string was the solution. I had to learn giving users to databases in SQL and adding reading privileges. Now it work perfectly!

Best wishes,
Zoli
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900