开发者

windows service sql connection problems

I need your help !!!!

I want to connect to sql server from a windows service, but it throw following exception :

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

My connection string is declared as follow:

<add name="CoreConnectionString" 
     connectionString="Data Source=10.10.2.102;Initial Cata开发者_Python百科log=DataBaseName;
                       Integrated Security=True" 
     providerName="System.Data.SqlClient" />

When I use user name and password instead of Integrated Security=True It works but in final deployment I cannot use user name and password.

What is wrong what can I do????


When you define Integrated Security=True in your connection string, whatever user is currently logged in will try to connect to your database. When running this as a console or Winforms app, this is your own user account.

However, if you run it as a Windows NT Service, it's the service account that this service is running under - in your case obviuosly NT AUTHORITY\ANONYMOUS LOGON.

And the error says it clearly: this user account does not have the permission to connect to the SQL Server.

You have several options:

  • stop your NT service and change the service account to be someone who does have access to the SQL Server

  • allow the NT AUTHORITY\ANONYMOUS LOGON to log into your SQL Server and use your database

  • create a specific user (e.g. an "application user") in your SQL Server and change your connection string to use that user specifically:

    connectionString="Data Source=10.10.2.102;Initial Catalog=DataBaseName;
                      user id=Your-Application-User-here;password=The-Secret-Password"
    
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜