简体   繁体   中英

Unable to connect to SQL server through Azure web app

I'm remotely debugging a web app hosted on Azure to try and find out why I can't do anything related to database access. I find that I get this error when I try to write to the database (I haven't tested if it happens when I read):

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)

My current Azure subscription is the free trial if that makes any difference. I don't know how I would enable remote connections for an Azure SQL server. I can connect to my server fine from my local machine as I have added its' IP to the server's firewall.

I'm sorry for the vague question but I have nowhere to go with this.

Do you have your connection string set up correctly?

Try the various options here: https://www.connectionstrings.com/sql-azure/

try the user ID as: username@servername.database.windows.net

There is an option with the SQL Server Network and Firewall that should be turned on in order to be able to access it from within Azure App Services.

Allow Azure Services

  1. Go to Firewalls and virtual networks on your SQL Server
  2. Turn 'Allow Azure services and resources to access this server' to 'Yes'
  3. Save your changes
  4. Now you should be able to access the SQL Server

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