具有集成安全性的 WCF Nhibernate 服务=True 错误
我正在开发 WCF 服务(使用 Fluent NH 实现),它作为 Windows 服务托管。
我正在使用控制台应用程序来测试调用服务方法。
现在,当我在 hibernate.cfg.xml 中设置连接字符串时,
<property name="connection.connection_string">Server=dev;Initial Catalog=DBTest;Integrated Security=True;</property>
它会抛出错误: SqlException: 用户登录失败
但是如果我将连接字符串更改为:
<property name="connection.connection_string">Server=dev;Initial Catalog=DBTest;User Id=twr;Password=manager1;</property>
它会成功调用服务方法。
虽然所有 WCF 服务库、托管 Windows 服务和控制台应用程序仅位于我的本地计算机上,但
任何人都可以帮助我理解为什么它不能与 Integrated Security=true 一起使用吗?
谢谢你!
I am working on a WCF Service(implemented with Fluent NH), and it is hosted as a Windows Service.
I am using a console application to test calling service methods.
Now, when I set connection string in hibernate.cfg.xml as
<property name="connection.connection_string">Server=dev;Initial Catalog=DBTest;Integrated Security=True;</property>
It throws the error:
SqlException: Login failed for user
But if I change connection string to:
<property name="connection.connection_string">Server=dev;Initial Catalog=DBTest;User Id=twr;Password=manager1;</property>
It successfully calls the service methods.
While all WCF Service Library, Hosting Windows Service and Console Application sits on my local machine only,
Can anyone please help me in understanding why it doesn't work with Integrated Security=true?
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
Integrated Security = true 意味着该应用程序将尝试在您连接的 SQL Server 上使用“Windows 身份验证”模式对自身进行身份验证。该服务在特定用户帐户下运行 - 它将使用该用户的帐户权限登录 SQL。
如果您的 SQL Server 实例不允许该 Windows 服务的用户帐户登录,您将收到该错误。单元测试中运行服务的用户很可能与测试控制台应用程序不同。
试试这个 - 运行您的测试控制台应用程序并打开任务管理器。在“进程”选项卡下,查看与您的服务关联的进程及其运行时的用户名。运行您的单元测试框架并记下用户名 - 它们可能不同。
转到 SQL Server Management Studio 并检查安全性 -> 下的情况。登录是否列出了运行服务的帐户(您使用任务管理器找到的帐户)。如果没有,请添加它并授予其权限。
Integrated Security = true means that this application will attempt to authenticate itself using "Windows Authentication" mode on the SQL Server you're connecting to. The service is running under a particular user account - it will use that user's account permissions to login to SQL.
If your SQL Server instance does not permit the user account of that Windows Service to login, you'll get that error. It's quite likely that the user the service runs as in your unit test is different than the test console application.
Try this - run your test console application and bring up Task Manager. Under the processes tab, look at the process associated with your service and the username it is running under. Run your unit test framework and note the username as well - they're probably different.
Go to SQL Server Management Studio and check to see under Security -> Logins whether the account that the service runs as (the one you found by using Task Manager) is listed. If not, add it and grant it permissions.