简体   繁体   English

在IIS中托管后无法连接SQL(模拟)

[英]Unable to connect the SQL after hosting in IIS (Impersonation)

I have a MVC application which uses 2 different DB in different server.One DB uses Service account and another uses windows authentication. 我有一个MVC应用程序,它在不同的服务器上使用2个不同的数据库。一个DB使用服务帐户,另一个使用Windows身份验证。 The windows username is from a different domain. Windows用户名来自其他域。 So I Impersonate the windows user and queried DB using ADO.Net. 因此,我使用ADO.Net模拟Windows用户并查询数据库。

using (new Impersonation(domain, username, password))
{
   //code to fetch the data using ADO.Net
}

I got this code from the below link. 我从下面的链接中获得了这段代码。

How do you do Impersonation in .NET? 您如何在.NET中进行模拟?

It is working fine in my local machine. 在我的本地机器上运行正常。 But when I published to IIS I am getting the below error. 但是,当我发布到IIS时,出现以下错误。 (DB which uses service account is working fine) (使用服务帐户的数据库工作正常)

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与SQL Server的连接时发生与网络相关或特定于实例的错误。 The server was not found or was not accessible. 服务器未找到或无法访问。 Verify that the instance name is correct and that SQL Server is configured to allow remote connections. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (提供者:命名管道提供程序,错误:40-无法打开与SQL Server的连接)

Do I need to add any permission or settings in IIS. 我是否需要在IIS中添加任何权限或设置。 IIS hosted Server doesn't have SQL Server Management studio to login and check. IIS托管服务器没有SQL Server Management Studio可以登录和检查。 Please help 请帮忙

Try to add 尝试添加

<system.web>
    <identity impersonate="true" userName="foo" password="bar"/>
</system.web>

above line in you Web.config file, "foo" and "bar" is username and password of the machine where your iis server is hosted. Web.config文件中的上一行,“ foo”和“ bar”是iis服务器所在计算机的用户名和密码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM