Results 1 to 4 of 4

Thread: connect windows service to sql

  1. #1
    hamid.abbaszadeh.mail is offline C# Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2016
    Posts
    2
    Rep Power
    0

    connect windows service to sql

    i connect to sql in windows form with this connection string:
    SqlConnection conn = new SqlConnection("Server =localhost;" + "Trusted_Connection=yes;" + "database=dataone; " + "connection timeout=30");
    i want to connect it in windows service app but i cant .
    can u help me
    thanks in advance

  2. #2
    jmcilhinney is online now C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    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.

  3. #3
    hamid.abbaszadeh.mail is offline C# Forum Newbie
    .NET Framework
    .NET 4.0
    Join Date
    Oct 2016
    Posts
    2
    Rep Power
    0
    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?

  4. #4
    jmcilhinney is online now C# Forum Moderator
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Posts
    1,468
    Rep Power
    118
    Quote Originally Posted by hamid.abbaszadeh.mail View Post
    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.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •