简体   繁体   中英

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. The windows username is from a different domain. So I Impersonate the windows user and queried DB using ADO.Net.

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?

It is working fine in my local machine. But when I published to IIS I am getting the below error. (DB which uses service account is working fine)

A network-related or instance-specific error occurred while establishing a connection to 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. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

Do I need to add any permission or settings in IIS. IIS hosted Server doesn't have SQL Server Management studio to login and check. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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