0

We have setup where our applications are hosted in Azure Virtual Machine, and our Databases are hosted in SQL Managed instance. Both are in same region, same subscriptions, but different Vnet as is the requirement of SQL Managed Instance.

We have whitelisted the IPs, open the port on NSG of both VM and SQL Instance.

We are able to open SQL in SSMS, in the local machine as well as in the VM itself. But for some reason same server does not work when added in the connection string.

We have tried with both 1433 and 3342 ports. We have tried proxy vs redirect We have tried VNET Peering as well, But nothing seems to work, we always get below 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.)'

Our applications are based on .Net.

We are moving our servers from on-premise to Azure.

Any help will be appreicated.

Thank you.

Neelam
  • 1,028
  • 12
  • 25
  • _does not work when added in the connection string_ What connection string? A connection string used in a web app? Where is the web app run? I'm guessing not on the VM that you are testing from. – Nick.Mc Dec 23 '21 at 06:30
  • Hi Nick, Yes, connectionstring in the web.config of our .Net App Which goes like Server=tcp:XXXXXXXXXXX.database.windows.net,1433;Persist Security Info=False;User ID=XXXXXX;Password=XXXXXXXXX;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30; – Neelam Dec 23 '21 at 07:17
  • Yes but where is your web app _running_? is it running on the VM or is it running, for example, in an _App Service_? Wherever your web app is running, it doesn't have connectivity. Until you can work out where it's running, you can't troubleshoot this. – Nick.Mc Dec 23 '21 at 07:59
  • Its running on VM. But We found a solution. Though the VNET peering is still not working, but after going through all the settings from Vnet/NSG/RouteTables. It seems that public link was working all along. the private and public endpoint have a difference of "public" text in the link. We missed that out earlier. Thank you – Neelam Dec 23 '21 at 08:30

1 Answers1

0

As both Virtual Machine and SQL managed instance are in different VNETs, we need to do VNET peering to allow the applications in the Virtual Machine to connect to SQL Server.

Now, we need to write NSG rules to allow Virtual Machine to connect to the SQL server through 1433, 3342 and 4022 ports.

Then your application in the virtual machine will be able to connect to the SQL server

To access the SQL server through public link, we have to whitelist the IP address of the virtual machine.

To access the SQL server through private endpoint, we need to host the private endpoint in the same VNET of the SQL server. Then through VNET peering, the application in the VM can access the SQL server.

RamaraoAdapa
  • 2,837
  • 2
  • 5
  • 11