Connecting to an external MS SQL Database using Azure - sql-server

I published my website using Azure and when I go to the sie I'm getting a SQL error:
SqlException (0x80131904): A network-related or instance-specific error occurred while establishing a connection to SQL Server.
I am assuming:
That Azure cannot find/process the connection to the external MS SQL server that is in the web.config file. I know that the settings are correct because when I launch the site locally, it connects to the database and retrieve the data.
It could also be that I'm using the free (one month) subscription and I'm not sure if that feature is supported.
I found an article (http://blog.davidebbo.com/2012/09/managing-database-connections-in-azure.html) that spoke about "Managing database connections in Azure Web Sites", but I cannot seem to be able to replicate the steps necessary to achieve this external connection.

I think it is nothing to do with your webapp or Azure Subscription. I understand that you are trying to connect your on premise database from your Azure app. It wont work directly and you need to establish a hybrid connection for the same. You can find the guidance here.

Related

Connect to Internal SQL database from Azure Web Application

I'm trying to build a webservice that talks to a SQL database hosted on a server in our internal network. The service is hosted by Azure as a Web App. Is there a good way of doing this? Do I have to use Azure Sql databases, and if I do, is there a way to have the Azure database act as a proxy for our internal database?
There are already rules permitting connections to the ports on our database server, so I don't think that's the problem. I see a lot of questions regarding connecting to Azure hosted sql databases, but nothing about connecting Azure web apps to other kinds of databases.
The error occurs when I try to call a stored procedure (via generated entity framework code) and is as follows:
Error occurred: System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> 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.
Our database is configured to allow remote connections, so what I'm guessing the Web App is having difficulty connecting to our vpn.
Please let me know if you need any additional information.
Thanks,
Josh
You can leverage Azure Hybrid Connections which is a feature of App service. Within App Service, Hybrid Connections can be used to access application resources in other networks. It provides access from your app to an application endpoint and uses Azure Relay service to connect to on-premise.
Check out the below link for more details :
https://learn.microsoft.com/en-us/azure/app-service/app-service-hybrid-connections
First option is to look on azure app service hybrid connection but for you to do that you should have Windows server 2012 or above.
Azure App Service Hybrid
Azure App Service hybrid connection is good if you are pulling small amount of data.
If you are pulling large amount of data or your SQL server version is below server 2012 you have two options:
Azure Site to Site VPN
Azure SQL Data Sync
Azure SQL DB Sync is a feature that available on Azure SQL database. You can create a Azure SQL database on azure and sync your on-premise SQL database or SQL database table to Azure SQL database and you can connect your application to Azure SQL database instead of connecting to on-premise database server. This will increase your performance of your application.
We ended up adding the application to an Azure Virtual network that allowed connections to our on-prem servers. The remaining difficulties were due the wrong port numbers being open.
What was very helpful in debugging this was the Kudu console in Azure, under Advanced tools -> console. There you can run commands from the machine hosting your application like ping, or the below:
sqlcmd -S tcp:servername,1433 -U Username -d databasename -P password -q "SELECT * FROM tablename"

Query of on-premises SQL Server from Azure web app (over Azure S2S VPN) fails

Our infrastructure team has worked to configure a site-to-site Azure VPN connection between our Azure subscription and our on-prem firewall, essentially following these steps. To test this, we've created a simple Azure web app that makes a query against a SQL Server that is located on-prem behind the firewall.
This web app works locally with no issues. Furthermore, the same code and connection string, when compiled as a console application and run on an Azure virtual machine, works correctly as well. But when deployed to the web app in Azure, the connection to the SQL Server fails:
[Win32Exception (0x80004005): The wait operation timed out]
[SqlException (0x80131904): 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: TCP Provider, error: 0 - The wait operation
timed out.)]
Both the Azure VM and web app are configured to point to the Azure VNet. It seems like something is preventing the web app from communicating with the SQL Server on its default port (1433). If I open up the web app's debug console and do a tcpping at the SQL Server with the default port (80), it returns successfully. But a tcpping to port 1433 times out.
It doesn't appear that the Azure Network Security Group is blocking that port:
The only solutions I've found that are relevant to our specific setup basically boil down to "use Azure Hybrid Connections instead", which would not be our first choice.
After working with Microsoft's support, the following changes were made and the VNet integration is working now. I apologize for the lack of detail on some of these, but our infrastructure team did most of the troubleshooting. Hopefully, some of these items will help point someone else the direction of a solution for their setup:
Initially, the connection was being made through public internet and not the VNET Integration and VPN. We identified that the VNET integration was failing due to the tunnel type being used. Azure App Service has a requirement that the tunnel type is SSTP. Once we changed it and synced the network, we were able to tcpping the SQL Server through its private IP.
We noticed it had to allow on the on-premises Network the point-to-site address pool. As a workaround, we decided to use the New VNET Integration (Preview). We created an empty subnet and were able to use this new feature.
We noticed then the App Service was not using the custom DNS. To resolve this, we added the DNS on the Virtual Network and also in the App Settings ("WEBSITE_DNS_SERVER") for the web app.

Azure SQL DB connecting to local SQL

I'm trying to connect from my azure SQL DB to link to the local SQL DB and create some linked tables that i can run some reports on within the Azure environment.
I've tested that i can follow the steps and successfully connect to another SQL Db within my Azure environment and this is working fine, so the steps i am following are correct.
However when i try to run the same steps connecting against my local DB i receive the following error:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
Steps i'm following are
Create Database scoped creds (using my same details that can log on via Management Studio)
create external data source
Create external table using the details created above.
This creates a external table within my azure database but when i try to select from this table i get the following message
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.)
So two questions really as i've googled for some time and a lot of the posts I've found seemed to be old.
Does Azure support connecting to a local DB?
And if so any ideas what this message means?
I've read up about this and the only comments i could see mentioned TrustServerCertificate=True to false. However i'm not sure where this is set and where the change is required? to me this looks more like a change within a connectionstring for coding rather than a db to db?
Elastic queries allow a query to span multiple Azure SQL Databases but on-premises SQL Server instances can not be part of elastic queries.
My suggestion is to perform replication of on-premises databases to Azure SQL Database or use SQL Data Sync so you can have an always updated copy of on-premises databases on Azure SQL Database and you can then query them as local tables or with elastic queries on Azure SQL Database.

Elastic query - SSL error

I am stuck with the same situation mentioned here in this URL.See SO question Here
. I am having a Azure VM and Sql Azure db. From Sql Azure Db i am using external table to query Azure VM Sql but with error:
The underlying error message received was: 'A connection was
successfully established with the server, but then an error occurred
during the login process. (provider: SSL Provider, error: 0 - The
certificate chain was issued by an authority that is not trusted.)'.
I knew its a CA certificate error. But I cant purchase certificate as of now. So I wanted to if i can use self signed certificate for the same.
I am having a certificate in my Azure VM. See below in screenshot. Will it work? Do I need to install that in my Sql Azure Db too?
If you are talking about Azure SQL Database elastic queries they can only be created between Azure SQL databases. You will find more information here.
Linked servers to SQL Azure databases are now supported as demonstrated here.
Hope this helps.
Regards,
Alberto Morillo

Unable to connect with the Windows desktop application using the Windows Sql Azure connection string?

we are using the window Azure first time and we have deplyed our SQL server databases on the window Sql Azure server. using the connection string from the SQL Azure server, we are able to successfully connect with the Web aapplication while at the same time when we are trying to connect with the Desktop application it always throw "General Network Error"?
In order to resolve the issue we have check the firewall and all seems to be fine.
Any help highly appreciated.
Thanks,
Rupesh
May I ask where your web application is running? It seems it is running in Windows Azure and connected to SQL Azure without any problem. Isnt it? I am always interested to know what tool you are using to connect? SSMS or SQLCMD or something else?
IF you want to connect SQL Azure from on premise (from your desktop) you really need to add your IP address in SQL Azure firewall exception list first. Even when you checked it that could be the main reason. Here is the guideline connecting SQL Azure DB and please follow first 3 points when you are trying to connect from your desktop. Those 3 points are:
Add your IP address in SQL Azure Exception List and add 1433 Port exception in your own firewall exception list
Verify you have setup firewall exception correctly
Always use login1#servername when connecting to SQL Azure DB nane XXXX.database.windows.net
After that try using SqlCmd as described here.

Resources