数据库连接模拟失败
我有一个 SL4 应用程序,它使用 WCF 与后端 SQL Server 2008 数据库进行通信。由于调用的存储过程需要数据库权限,其中一项 WCF 服务需要使用专用系统帐户连接到数据库。我尝试在服务代码中使用模拟来实现解决方案,例如
int result = LogonUser(userName, domain, password,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, out _token);
if (result > 0)
{
ImpersonateLoggedOnUser(_token);
//Code here to call NHibernate data access code
}
此服务的我的连接字符串是:
<add name="MyConnection" connectionString="Data Source=servername\instance;Initial Catalog=MyDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
但是,数据访问例程仍然失败,并显示以下消息:
用户“NT AUTHORITY\ANONYMOUS LOGON”登录失败。
数据库连接中的模拟被忽略。有什么想法吗?
I have a SL4 app that uses WCF to communicate with a backend SQL Server 2008 database. One of the WCF services needs to connect to the database with a dedicated system account due to the database permissions required by the stored procedure that is called. I have attempted to implement a solution using impersonation within the service code e.g.
int result = LogonUser(userName, domain, password,
LOGON32_LOGON_NETWORK, LOGON32_PROVIDER_DEFAULT, out _token);
if (result > 0)
{
ImpersonateLoggedOnUser(_token);
//Code here to call NHibernate data access code
}
My connection string for this service is:
<add name="MyConnection" connectionString="Data Source=servername\instance;Initial Catalog=MyDatabase;Integrated Security=SSPI" providerName="System.Data.SqlClient"/>
However, the data access routine is still failing with the following message:
Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.
The impersonation is being ignored in the database connection. Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
在对
LogonUser
的调用中,将LOGON32_LOGON_NETWORK
更改为LOGON32_LOGON_NETWORK_CLEARTEXT
。这会将登录凭据缓存在本地安全提供程序中,这应该能够与 SQL Server 成功进行 SSPI 握手。
Change
LOGON32_LOGON_NETWORK
toLOGON32_LOGON_NETWORK_CLEARTEXT
in your call toLogonUser
.This caches the logon credentials in the local security provider, which should enable a successful SSPI handshake with SQL Server.
实际上,我已经成功地通过摆脱模拟 API 代码并将以下内容添加到我的 web.config 中来使其正常工作:
该服务在我的专用系统帐户的上下文中运行,并使用相同的上下文连接到 SQL。
I've actually managed to get this to work by getting rid of the impersonation API code and adding the following to my web.config:
The service runs under the context of my dedicated system account and connects to SQL using the same context.