windows服务sql连接问题

windows service sql connection problems(windows服务sql连接问题)
本文介绍了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连接问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)
How can I generate an entity–relationship (ER) diagram of a database using Microsoft SQL Server Management Studio?(如何使用Microsoft SQL Server Management Studio生成数据库的实体关系(ER)图?)