Here is the situation:
- SQL Server database is hosted in the cloud.
- Remote access is allowed.
- User ID & Password are provided in the connection string in web.config file in root folder.
- Test connection is successful.
- The Web app has multiple folders with role based authorization. Each folder has its own
web.config
file for authorization.
Everything works fine when I run the app in debug mode from Visual Studio 2019.
Problem:
When I publish/host the app on shared server provided by same service provider that hosts the database, the app is unable to locate the server/database.
I have narrowed down that the block of code in web.config
file responsible for authorization is causing the problem.
When authorization is removed, access to database is fine. But when I put folder level authorization, app is unable to locate the server/database.
This is the error :
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: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Following two methods were tried separately and are causing this problem.
Method 1:
<authorization>
<allow roles="ADMIN"/>
<deny users="*"/>
</authorization>
Method 2:
<location path="PagesAdmin">
<system.web>
<authorization>
<allow roles="ADMIN"/>
<deny users="*"/>
</authorization>
</system.web>
</location>