Rahul Dev
Rahul Dev

Reputation: 141

How to connect an Azure SQL Managed Instance to an Azure App Service (written in .NET Core 2.2)

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?

Upvotes: 1

Views: 6835

Answers (2)

Sajeetharan
Sajeetharan

Reputation: 222722

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

Upvotes: 1

Leon Yue
Leon Yue

Reputation: 16431

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.

Upvotes: 1

Related Questions