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连接问题
- 使用 Oracle PL/SQL developer 生成测试数据 2021-01-01
- 如何将 Byte[] 插入 SQL Server VARBINARY 列 2021-01-01
- 以一个值为轴心,但将一行上的数据按另一行分组? 2022-01-01
- 远程 mySQL 连接抛出“无法使用旧的不安全身份验证连接到 MySQL 4.1+"来自 XAMPP 的错误 2022-01-01
- 导入具有可变标题的 Excel 文件 2021-01-01
- 更改自动增量起始编号? 2021-01-01
- 在SQL中,如何为每个组选择前2行 2021-01-01
- SQL 临时表问题 2022-01-01
- 如何将 SonarQube 6.7 从 MySQL 迁移到 postgresql 2022-01-01
- 如何使用 pip 安装 Python MySQLdb 模块? 2021-01-01
