将 Windows 身份验证集成到 SQL Server
我有一个使用 SQL Server 上的数据库的应用程序,我希望用户使用集成 Windows 身份验证连接到该服务器。连接字符串是:
SqlConnection scn = new SqlConnection("Data Source='server name';Initial Catalog=temp;Trusted_Connection=true;Integrated Security=SSPI");
当我从我的电脑运行该应用程序时,它工作得很好并且可以识别我的用户名。但是当我从服务器运行它时,它会出现以下错误:
用户“domain\server Name$”登录失败。
据我了解,它无法识别用户名,并认为用户名是服务器名称。
知道如何修复它吗?
I have an application that uses a database on SQL Server and I want users to connect to that server using integrated windows authentication. The connection string is:
SqlConnection scn = new SqlConnection("Data Source='server name';Initial Catalog=temp;Trusted_Connection=true;Integrated Security=SSPI");
When I run the application from my pc it works just fine and it recognizes my user name. But when I run it from the server then it gives me the following error:
Login failed for user 'domain\server Name$'.
As I understand it doesn't recognize the user name and thinks that the user name is the server name.
Any idea how to fix it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
应用程序作为服务器计算机帐户正确连接。作为
LocalSystem
或Network Service
运行的进程通过网络作为机器domain\machine$
进行身份验证,这是设计使然、有意为之。您可以根据需要授予
domain\server$
登录 SQL 的权限。或者您可以更改应用程序以在不同的帐户下运行(我假设该应用程序是一项服务?)。The application correctly connects as the server machine account. Processes running as
LocalSystem
or asNetwork Service
authenticate over the network as the machine,domain\machine$
, this is by design, intentional and desired.You can grant
domain\server$
login rights into SQL as needed. Or you can change the application to run under a different account (I assume the application is a service?).使用
runas
运行应用程序具有正确的凭据。Use
runas
to have the application run with the correct credentials.