简体   繁体   中英

Cannot access SQL Azure DB from Azure website but same connection string works from local website

I am unable to access SQL Azure DB from Azure website even though same connection string works from local website. The error is as follows:

System.Data.SqlClient.SqlException (0x80131904): Login failed for user 'XYZ'.
at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception,
Boolean breakConnection, Action`1 wrapCloseInAction) at
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, 
Boolean callerHasConnectionLock, Boolean asyncClose) <...>  
Error Number:18456,State:1,Class:14  <...>

After checking previous answers,

  1. I have made added my database to my website's linked resources on Azure portal. 在此输入图像描述
  2. I have added 0.0.0.0 - 255.255.255.255 range to my firewall exclusion list Not needed! 在此输入图像描述
  3. I have made sure that my connection string usage does not allow any ambiguity .
  4. I have made sure that ApplicationDbContext is built using correct connection string .

What else I could try?

The website code is here .

I'm not sure which portal you're using, but... in the preview portal (portal.azure.com), your database settings page will have a link to the server, and there you'll find firewall settings. And aside from IP ranges, there's an option to allow Azure services to have access to your database. You'll need that enabled.

Same thing in manage.windowsazure.com - the settings are accessible through the Configure tab.

I needed to update my website settings as in Cannot Access Azure DB Server from Azure Website , needed to copy-paste the whole connection string as the second parameter. The third parameter in these settings that worked for me was SQL Server .

This makes sense in my case because I deploy on Azure through github. Obviously when you upload my web.config on github, I take my database password out, the connection string from uploaded web.config as uploaded on github cannot be used to gain access to the database. So it makes perfect sense to specify the connection string(s) on Azure website, because the information I provide there remains private. Presumably, this is done using XDT as shown here .

Firewall settings modifications were unnecessary.

The error you are getting is not due to a firewall ACL issue with SQL Azure. That error would say something like this error in the screenshot below. You must have an issue instead with your connection string.

Do also make sure in your SQL Azure server ACL settings you have the option checked to allow Azure services to connect to 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