windows service sql connection problems

旧巷老猫 提交于 2019-12-05 13:06:18

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"
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!