問題描述
我需要你的幫助!!!!!!
I need your help !!!!
我想從 Windows 服務連接到 sql server,但它拋出以下異常:
I want to connect to sql server from a windows service, but it throw following exception :
用戶NT"登錄失敗權威\匿名登錄'.
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 Catalog=DataBaseName;
Integrated Security=True"
providerName="System.Data.SqlClient" />
當我使用用戶名和密碼而不是 Integrated Security=True 時它可以工作,但在最終部署中我不能使用用戶名和密碼.
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????
推薦答案
當您在連接字符串中定義 Integrated Security=True
時,當前登錄的任何用戶都將嘗試連接到您的數據庫.將此作為控制臺或 Winforms 應用運行時,這是您自己的用戶帳戶.
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.
但是,如果您將它作為 Windows NT 服務運行,則該服務是在該服務帳戶下運行的 - 在您的情況下顯然 NT AUTHORITY\ANONYMOUS LOGON
.
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
.
并且錯誤明確指出:此用戶帳戶沒有連接到 SQL Server 的權限.
And the error says it clearly: this user account does not have the permission to connect to the SQL Server.
您有多種選擇:
停止您的 NT 服務并將服務帳戶更改為有權訪問 SQL Server 的人
stop your NT service and change the service account to be someone who does have access to the SQL Server
允許 NT AUTHORITY\ANONYMOUS LOGON
登錄到您的 SQL Server 并使用您的數據庫
allow the NT AUTHORITY\ANONYMOUS LOGON
to log into your SQL Server and use your database
在您的 SQL Server 中創建一個特定用戶(例如應用程序用戶")并更改您的連接字符串以專門使用該用戶:
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"
這篇關于windows服務sql連接問題的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!