简体   繁体   中英

Why is IIS7 blocked from accessing my database when connecting to a website via a browser from a client machine?

When I access the website from the same machine IIS is running on I am able to connect to the database, but not if I try to access it remotely. The only way I've managed to get it to connect is when I specify Physical Path Credentials:

click to open image

This doesn't work for me because, I am using the username as a search criteria when querying the database and this way I always get the same username (the one I specified in the physical path credentials).

I am confused because, when accessing the website locally and remotely I use the same credentials and I get different results.

This is the exception that is thrown when trying to access the site remotely:

ByNadexLoginSystem.Exception: System.Exception: 'SelectDataObject()' failed ---> System.Data.SqlClient.SqlException: 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) ---> System.ComponentModel.Win32Exception: Access is denied --- End of inner exception stack trace

I have tried adding folder permissions as pointed out here: ASP.NET Application page not working on clients computers with no success whatsoever.

The SQL server is configured to allow remote connections.

I am sure it is a permissions problem I just can't find where. Any ideas?

I found the solution to my problem, I want to give credit to Sean Lange . Thanks to his question it gave me a line of investigation to follow. While going through msdns documentation here https://msdn.microsoft.com/en-us/library/bsz5788z.aspx I found this:

If SQL Server is on a different computer than the Web server, the Windows identity must be able to flow across the network to the remote instance of SQL Server. (Windows networks that have been configured appropriately with Kerberos authentication are able to do this.) However, depending on the settings in the identity configuration element, the Windows identity established on the operating system thread for ASP.NET applications may not be able to flow properly to the remote SQL Server.

In IIS, only Basic Authentication logs users on with a security token that flows across the network to a remote SQL server. By default, other IIS security modes used in conjunction with the identity configuration element settings will not result in a token that can authenticate to a remote SQL Server.

Enabling Impersonation and Basic Authentication ( disabled Windows Authentication ) solved it!

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