简体   繁体   中英

Can't connect to SQL Database from Azure Application Service

I have two Application Services running .NET Core 3.1 apps that connect to an Azure SQL Database. One app is a simple test app to test connectivity to the database using the same DI pipeline, the other is the full application. The test application connects to the database and produces the desired output while the production application fails to connect with the following exception message:

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: SNI_PN11, error: 26 - Error Locating Server/Instance Specified)

I've modified the rules on the database to include my development workstations IP address and both applications connect to the database as expected. On the database firewall, I've also done the following:

  1. Added the IP address for the test and production apps to the database firewall. It's the IP address designated as virtual ip address in the properties section of the App Service. The two app services share a virtual IP address.
  2. Enabled the Allow Azure services and resources to access this server setting in the console.

The applications' appsettings.json files are identical.

When I deploy the test app to the production server it still works. Something in the production app is causing the connection to fail. Why can't the production app connect and what else can be done to troubleshoot the issue?

Wondering if there was something wrong with my connection string, I added some logging to write it out to the log file. I realized the connection string was wrong - it was trying to connect to a different database. AppSettings.Production.json was overriding the connection string, my test app had an empty AppSettings.Production.json which is why it worked.

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