Error loading my web app after deploying .NET Core console app to Azure - asp.net

My app is running locally without any issue but when I try to run it from Azure console I have the following error :
An error occurred while starting the application.
SqlException: Cannot open server 'Server-name' requested by the login. Client with IP address 'w.x.y.z' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.
Microsoft.Data.ProviderBase.DbConnectionPool.CheckPoolBlockingPeriod(Exception e)
SqlException: Cannot open server 'server-name' requested by the login. Client with IP address 'ip' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule
I have added IP in firewall setting on azure portal still the issue is happening

This error was caused because your IP was not added in the SQL server tab(azure portal). So you must add the IP address of your SQL Server on Azure portal

You have to update the settings of the "Firewalls and virtual networks" of your SQL Server.
Browse to your SQL Server, add the IP address and allow other azure services and resources to access the server. Refresh and wait at least 5 minutes before trying again.
I also had my ubuntu server firewall blocking my request once, so be sure your webserver is not responsible.

Have you tried enabling this setting?

Related

Azure SQL - localhost can't connect

I started coding an ASP.NET webapp (with Visual Studio 2015). I'm having problems with the connection to my Azure SQL database. I can connect to the database via MSSM Studio.
When I publish my app on the Azure webservice the app works fine. When I run my code locally I keep getting the following error:
SqlException: Cannot open server 'database' requested by the login. Client with IP address 'XX.XX.XX.XX' is not allowed to access the server. To enable access, use the Windows Azure Management Portal or run sp_set_firewall_rule on the master database to create a firewall rule for this IP address or address range. It may take up to five minutes for this change to take effect.
Altough the firewall of the database service is set (I've even tried with range 0.0.0.0 too 255.255.255.255). On my computer port 1433 is allowed.
Any help is deeply appreciated.
The problem was solved by editing the username of the database connectionstring.
my_username#my_app.database.windows.net -> only worked published on Azure (not via localhost)
my_username#database.windows.com -> works published on Azure and with my localhost

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!

azure connect between azure myWebRole and nonazure server not working

My webapplication hosted on windows azure, needs to communicate with TFS Server. When any one login to my web app using live id, I want the logged in user to use my Team foundation server(TFS) credentials -username,password and domain to programatically authenticate and connect to our TFS server and create some work items.
I configured my azure connect for the communication to happen between azure WebRole and TFS server (our TFS is non-azure ).I added both the WebRole and the TFS Server into single Connection Group
In my azureportal ,I can see mywebrole and my TFSServer as connected the machine endpoint is active, and that it refreshes since the last connected updates
.But when I try to run my web application from azure and when it tries to communicate with our TFS server ,its throwing error message saying Error message : Team Foundation services are not available from server eg.,http://xyz-abcxyx-01:8080/tfs/eas/. Technical information (for administrator): The remote name could not be resolved: 'xyz-abcxyx-01'
Any suggestions to resolve this issue ?
You should enable remote desktop on your WebRole and connect to one of your instances. Then, try to ping the IP of your TFS server (not the hostname xyz-abcxyx-01). Maybe this is simply a DNS issue (even though using hostnames works with Windows Azure Connect).
If pinging the IP works, but pinging the hostname doesn't work you have a few options left:
Use the IP instead of the hostname. This won't work if you configured your TFS to use host headers.
Create an elevated startup task to modify the hosts file and map the IP to the hostname. In your code you can keep working with the hostname.
Try to modify the DNS server configured in your WebRole to use the default DNS server + your internal DNS server. But to me this doesn't look like a clean solution.
Anyways, in each solution you'll want to store the IP/hostname in the ServiceConfiguration and make sure your code supports changes to the ServiceConfiguration. This will allow you to change the IP/hostname without having to redeploy.
You should check if TFS server is listening on all network interfaces, include the one created by Azure Connect (start with 2a01). Next try to connect to TFS from a machine on the local LAN, just to make sure it is configured correctly. You don't need to use IP for referring to TFS, DNS name is definitely supported out of box.

Why I am not able to connect to remote SQL Server from asp.net website whereas it is connecting from SQL Server Management Studio

Why I am not able to connect to remote server from asp.net website whereas it is connecting from SSMS
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)
I tried all the possible solution suggested in this link
I checked Followings as given in the above article, they are enabled/running
SQL Server is up and running.
TCP/IP enabled in SSCM
Opened port in Windows Firewall
Remote Connection enabled
SQL Server Browser Service running
I searched for sqlbrowser.exe but it is not found in the given directory.
Finally I switched off Windows Firewall but still it is not working.
UPDATE: we are connecting to sql server using a custom user created on sql server (not sa )
I have user account credential to Remote connect to server.
I tried to change LogOn to my credentials (administrator) . in Windows Services SQL Server (MSSQlServer) and SQL Server Agent (MSSQL Server) services.
Double check your connection string - are you connecting to a hostname that needs to be added to your Hosts file? For example "dev-sql1" but without a matching entry in dns or hosts file.
If you have created a custom user, can you check if logins are disabled for the user?
In SSMS, goto Security, right click user, Properties -> Status, Login - Enabled.
Hope this should fix it.
Three possibilities and they are not mutually exclusive.
Most hosting providers disable remote connections to SQL servers. Check with RackSpace if blocking port 1433
The SQL Server needs to be reconfigured to accept remote connections. See http://support.microsoft.com/kb/914277
You have to use a different connection string. See http://www.connectionstrings.com/sql-server and look for Connect via an IP address
I got the same issue but with mysql server. Rack space had two mysql server address. One for connecting from outside their local network and one for connecting from inside the network. you will have to use the address that is required to connect from inside the network.

Could not open a connection to SQL Server

I have problems connecting to my database server. The database server is not local, I am connected via its IP address.
It works fine in my development machine. After publishing the website to my server, it can not connect to my database server.
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)
Why can't my publish server connect to the database server, whereas it works fine through the development machine?
I often had that problem. Mostly it's because of two problems.
Open the SQL Server Configuration Manager.
Check if the SQL Server Network Configuration supports TCP/IP, if it's disabled, enable it.
e.g. SqlServer 2005 Network Configuration, Protocols for SQLEXPRESS
Open the SQL Server Management Studio
Click on the Sql Server Properties (right click on the server name and
select properties).
After that, select the page "Security" and switch the check to "SQL Server and Windows Authentication mode".
That's all.
I'll attempt to go two for two on the psychic debugging for today...
I will assume that you are not using integrated security? If so it might explain things as the account on your local machine probably has permissions, but the SYSTEM account that is running on the server does not. Just a shot in the dark though.
It sounds like your server can't make the network connection, rather than a security issue.
Ensure that any firewalls on both the DB and app servers allow traffic on the port (1433).
Ensure you're able to ping or tracert from both machines.
Is it your first time you publish your website on the web server ? if it is , Are you sure you have set your connection string properly ?
You need to create a login ( of curse a password for that too ) and the IP Address of that SQL on the web server .
So you need IP Address of the sql server host , Database Name , UId , Pwd .
I will agree that this sounds like a network issue and not a security issue.
Remote into the web server and ping the DB server by IP address. If this does not work, your server cannot see the DB server via that address (different subnet, incorrect firewall/proxy setup, etc). There may be a proxy address you must use to get to the DB server from the web server, or your web server may also be the gateway and IIS doesn't know to look for the DB server on the LAN. If it does work, the computers may not be talking on the same port, or the firewall may be blocking that port exiting the web server.
I have spent hours trying to connect to SQL server using sqlcmd. I disabled my firewall, checked all ip listed in "Protocols for SQLEXPRESS", edited my hosts file. I tried using different ips and machinename to connect to the server. But none of work worked. After hours of investigation, I found out that I made absolutely stupid blunder making me unable to connect.
I want to remind people that the connection string is not case sensitive. But the option is!!
what i did is I put
sqlcmd -s .\sqlserver
But the correct string is
sqlcmd -S .\sqlserver
so watch out, people

Resources