1

I have a .NET Core 2.2 web app deployed to Azure App Service which I'm connecting to an Azure SQL managed instance. What should be the connection string that is to be written in Appsettings.json. I tried the below connection string which I found out in Azure portal but that is not working.

"AZURESQLCONNSTR_":Server=tcp:azure-abcde.database.windows.net,1433;Persist Security Info=False;User ID=userid;Password=password;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;

But when I try running the below Azure App Service I'm not getting any data.

http://productwebapp.azurewebsites.net/api/ProductDetails/GetProductDetails.

Can you please suggest a way to resolve this issue?

Rahul Dev
  • 141
  • 2
  • 17
  • did you get any connection errors? – Leon Yue Dec 13 '19 at 06:37
  • Did you follow this tutorial:https://learn.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-connect-query-dotnet-core? – Leon Yue Dec 13 '19 at 06:45
  • You can configure public endpoint in Azure SQL Database managed instance to allow azure app service to access the instance. For more details, please refer to https://learn.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-managed-instance-public-endpoint-configure – Jim Xu Dec 13 '19 at 06:52

2 Answers2

1

You will have to allow certain IP addresses to connect to it. Look at the SQL Database server's Firewall setting. You can the IP address of your computer (or IP range), to access SQL Database

Make sure to enable Allow Azure services and resources to access the server

enter image description here

EDIT:

Follow the resources

Create an Azure SQL Database managed instance

Connect an Azure App Service hosted application

Sajeetharan
  • 216,225
  • 63
  • 350
  • 396
  • @Sajeetharan- How to configure these IPs as I deployed my database to managed instance using VM and default power shell script which is provided while creating a managed instance. – Rahul Dev Dec 13 '19 at 05:48
  • Sorry then this is not the right answer, check the link https://learn.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-managed-instance-management-endpoint-verify-built-in-firewall – Sajeetharan Dec 13 '19 at 05:50
  • @Sajeetharan- I added port 9000,9003,1438,1440,1452 to the NSG of the Jumpbox and deployed the app once again but still not working. – Rahul Dev Dec 13 '19 at 06:10
  • try to connect from your local machine and see – Sajeetharan Dec 13 '19 at 06:16
1

As you said you have a .NET Core 2.2 web app deployed to Azure App Service, you want connect to an Azure SQL managed instance.

You web app is Azure App Service host application.

I think you may reference this tutorial: Connect an Azure App Service hosted application:

Managed Instance can be accessed only through a private IP address so in order to access it from Azure App Service you first need to make a connection between the application and the Managed Instance VNet. See Integrate your app with an Azure Virtual Network.

For troubleshooting, see Troubleshooting VNets and Applications. If a connection cannot be established, try synching the networking configuration.

A special case of connecting Azure App Service to Managed Instance is when you integrated Azure App Service to a network peered to Managed Instance VNet. That case requires the following configuration to be set up:

  • Managed Instance VNet must NOT have gateway
  • Managed Instance VNet must have Use remote gateways option set
  • Peered VNet must have Allow gateway transit option set

Another reference: https://learn.microsoft.com/bs-latn-ba/azure/sql-database/sql-database-connect-query-dotnet-core

Hope this helps.

Leon Yue
  • 15,693
  • 1
  • 11
  • 23