connect windows service to sql

Joined
Oct 29, 2016
Messages
2
Programming Experience
1-3
[FONT=&quot]i connect to sql in windows form with this connection string:[/FONT]
[FONT=&quot] SqlConnection conn = new SqlConnection("Server =localhost;" + "Trusted_Connection=yes;" + "database=dataone; " + "connection timeout=30");[/FONT]
[FONT=&quot]i want to connect it in windows service app but i cant .[/FONT]
[FONT=&quot]can u help me[/FONT]
[FONT=&quot]thanks in advance[/FONT]
 
First of all, what's the point in concatenating literal strings? Why do this:
SqlConnection conn = new SqlConnection("Server =localhost;" + "Trusted_Connection=yes;" + "database=dataone; " + "connection timeout=30");
instead of this:
SqlConnection conn = new SqlConnection("Server =localhost;Trusted_Connection=yes;database=dataone;connection timeout=30");
As for the issue, "I can't" is NEVER an adequate explanation of the issue. If it doesn't work as you expect then it does something else. What is that? If there's an exception then there's an error message. What is that? That will almost certainly tell you exactly what the issue is or point you in the right direction. My guess is that your service is running under a different user account than your Windows app and there is no SQL Server user with appropriate permissions that matches that user account.
 
ok my promlem was about user account. i solved it.but i want to use "sql table dependency" in windows service app .but i have no idea about it.where i have to write my code? in onstart or main loop?
 
ok my promlem was about user account. i solved it
In that case, mark this thread as Answered and then start a new thread for any new question you may have. One thread per topic and one topic per thread please.
 
Back
Top Bottom