Can't connect to Azure SQL Database from Azure Container Instances - azure

I've built a Windows container with my app inside and ran it locally. The app in the container connects to an Azure SQL Database, using the domain name from the connection string. SQL Server is configured to accept clients from any IP and from Azure Services.
Everything works fine locally. But when I run my container in Azure Container Instances, I get the following standard error:
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 - A connection attempt failed
because the connected party did not properly respond after a period of time,
or established connection failed because connected host has failed to
respond.)

You need to create a managed identity https://learn.microsoft.com/en-us/azure/container-instances/container-instances-managed-identity and grant that identity permission to the SQL database.
You can then use the Microsoft.Azure.Services.AppAuthentication library to get an access token and use it during authentication. This is only available in dotnetcore 2.2 and .net 4.6 and above.
string connectionString = "Data Source=<AZURE-SQL-SERVERNAME>; Initial Catalog=<DATABASE>;";
SqlConnection conn = new SqlConnection(connectionString);
conn.AccessToken = (new AzureServiceTokenProvider()).GetAccessTokenAsync("https://database.windows.net/").Result;
conn.Open();
More info can be found in the below links. None of them are explicitly for ACI but it should be basically the same from a code perspective once you have created the MSI.
https://learn.microsoft.com/en-us/azure/key-vault/service-to-service-authentication
https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/tutorial-windows-vm-access-sql
https://learn.microsoft.com/en-us/azure/app-service/app-service-web-tutorial-connect-msi

I've experienced a similar issue with a Windows container in ACI trying to connect to an Azure SQL database. For some reason, DNS was not working inside the container. I could not resolve any public DNS names. Inside the container, DNS was pointed to a 10.x.x.x address. I never set this as part of the image build so I assume ACI is setting this as part of DHCP.
To fix this I ran the following as part of my PowerShell entrypoint script:
$nic = Get-NetAdapter
Set-DnsClientServerAddress -InterfaceIndex $nic.IfIndex -ServerAddresses ('1.1.1.1','8.8.8.8')

Related

Connect Azure App Service and Azure SQL VM

I have a setup where the connection string of my .NET application is configured at the app service level and the database used in it is present in an Azure SQL VM
I see the following error, while accessing my Web APIs in the app service
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 - Access is denied.
However, I’m able to connect to the database directly on my local system using SSMS with my organisation’s VPN
I’m struggling to find the right resource, appreciate if you someone can help me with steps to fix it
i just have the beginner level knowledge on Azure platform
I tried to reproduce the same in my environment I got the same error like below.
To resolve this issue i have removed private access and tried and then added new private access its work successfully.
Check the public access in selected network with firewall rule and allow exception as below.
And, when I remove this private endpoint and try to add new private access i can able to connect with my sql server.
Check this connectivity as below.
My azuresql,database server connected successfully.
Note: This error may occur in multiple ways if are not enable sql services and in tcp/Ip If any of the protocols are disabled or if Remote Connection Permission is disable error may occur for this please refer the below documents.
Reference:
Microsoft SQL Server Error 2 Cannot Connect to Local: How to Solve? (systoolsgroup.com)
Resolving could not open a connection to SQL Server errors (mssqltips.com)

Azure SQL Managed Instance - SSMS Connectivity

I created a new Azure SQL Managed Instance and obtained the connection string from the Azure Portal. However, I am unable to connect to the server from SQL Server Management Studio. The connection hangs and times out with a network error.
You need to configure the public endpoint and ensure you're using the public connection string, including port 3342 at the end of it.
https://www.jamesserra.com/archive/2020/04/accessing-managed-instance-via-ssms/

How to migrate a dockerized SQL Server database that uses a custom port to Azure SQL

I am hosting a bunch of micro-services and bot apps using Docker, and Azure virtual machines. There´s also a dockerized SQL Server 2017 instance in the stack, which I would like to migrate to Azure SQL. I am out of luck when trying to configure the source database in an Azure Database Migration project...
I tried to specify the service endpoint including the exposed port (since the dockerized SQL Server container´s public port is not 1433). I can connect to the SQL Server instance using SSMS from my workstation with no error, so connectivity is not the problem at all; does the Azure Database Migration require port 1433, or if not, how can I correctly specify a different port?
These are the error details I got from source details configuration in the Azure portal:
Error Type
Failed to connect, please check error details
Error Detail
Collector 'Microsoft.SqlServer.Advisor.SqlQueries.Contracts.Models.IQueryServerProperties' failed to collect data. 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: 25 - Connection string is not valid)
The parameter is incorrect
The source database configuration wizard is not very clear about the format of the remote server´s DNS name. Just specifying the fully qualified DNS name and port is not enough; it must contain the server´s instance name as well.
Wrong:
<DNS-name>,<port>
Correct:
<DNS-name>\<INSTANCENAME>,<port>

RemoteApp working with Azure Windows Server 2012

Hoping someone can shed some light on my RemoteApp/Azure dilemma
I have successfully setup RDS on Server 2012 VMs in Azure - session host, rdweb and connection broker, opted not to have a gateway as only running one session host.
Created an self-signed certificate in RDS tools in Server Manager and bound this to rdweb, named the cert remote.cloudapp.net. I also uploaded this to the cloud service for the VMs using Azure powershell.
So via an Azure VM on the domain in Azure I can connect to remoteapp and successfully run an application.
However when I connect externally via a browser on my standalone laptop I get the following error in the RDS Log:
Remote Desktop Connection Broker Client failed to redirect the user
REMOTE\appuser. Error: NULL
I have tried the fix of look for an Pool ID of NULL in the Windows Internal Database and I only have one pool ID which is the collection I created, so can't be that.
Also get this error returned when I try to run a remoteapp after successfully logging into the RDweb page:
Remote Desktop Services cannot connect to the remote computer for one
of these reasons: Remote Access is not enabled to the server Remote
computer turned off Remote computer not available on the network
I am totally stumped, is there something I am missing that is so simple.

How to run the Azure Cloud Service without using Sql Azure Database?

My azure application successfully running with azure sql database,but now i want to run Cloud application with my own database servers because of their data security. for this, we can establish the local database connection from our own systems with cloud application and connect to my database perfectly with following steps using below link,
http://www.codeproject.com/Articles/261063/Azure-Virtual-Network-Connecting-Local-Database
After this i deployed my application in to azure and it deployed without any error.but when i try to run my cloud application using cloud url like xxx.cloudapp.net getting an error like
"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 requested name is valid, but no data of the requested type was found.)".
Please give some suggestions why am getting this error.
Thanks,
PCSSCP.
Try connecting using SQL Management from another machine outside of your network. I believe that there is no problem with publication in Azure Cloud Service, but a connectivity problem with your SQL server.
Arthur Oliveira
You have to remote to VM and check SQL Server port is opened or not, the same with SQL Server machine. I used to connect local DB with cloud based application.
This is an intermittent issue with the SQL Server.
Check this link if it helps,
IntermittentSQLServerIssue

Resources