windows service sql connection problems(windows服务sql连接问题)
问题描述
我需要你的帮助!!!!!!
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连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:windows服务sql连接问题
基础教程推荐
- 如何使用 mysql.connector 禁用查询缓存 2022-01-01
- SSMS 中的权限问题:“对象 'extended_properties'、数据库 'mssqlsystem_resource'、... 错误 229)上的 SELECT 权限被拒绝" 2022-01-01
- 需要 MySQL 5.1 中的抽象触发器来更新审计日志 2021-01-01
- 将 SQL Server DateTime 列迁移到 DateTimeOffset 2021-01-01
- SQL Server 实例在登录协商期间返回无效或不受支持的协议版本 2021-01-01
- 是否可以执行按位分组功能? 2021-01-01
- SQL 效率:WHERE IN 子查询 vs. JOIN 然后 GROUP 2021-01-01
- SQL:使用来自具有相同列名的两个表中的数据... 2021-01-01
- 无法解决整理冲突 2021-01-01
- 在 SQL 中连接多个表 2021-01-01
