Add a connection to Azure SQL Database
With Visual Studio, you can connect any of the following to Azure SQL database by using the Connected Services feature:
- .NET Framework console app
- ASP.NET MVC (.NET Framework)
- ASP.NET Core
- .NET Core (including console app, WPF, Windows Forms, class library)
- .NET Core Worker Role
- Azure Functions
- Universal Windows Platform App
The connected service functionality adds all the needed references and connection code to your project, and modifies your configuration files appropriately.
This topic applies to Visual Studio on Windows. For Visual Studio for Mac, see Connected services in Visual Studio for Mac.
- Visual Studio with the Azure workload installed.
- A project of one of the supported types
Connect to Azure SQL Database using Connected Services
Open your project in Visual Studio.
In Solution Explorer, right-click the Connected Services node, and, from the context menu, select Add Connected Service.
In the Connected Services tab, select the + icon for Service Dependencies.
In the Add Dependency page, select Azure SQL Database.
If you aren't signed in already, sign into your Azure account. If you don't have an Azure account, you can sign up for a free trial.
In the Configure Azure SQL Database screen, select an existing Azure SQL Database, and select Next.
If you need to create a new component, go to the next step. Otherwise, skip to step 7.
To create an Azure SQL Database:
Select Create a SQL Database at the bottom of the screen.
Fill out the Azure SQL Database: Create new screen, and select Create.
When the Configure Azure SQL Database screen is displayed, the new database appears in the list. Select the new database in the list, and select Next.
Enter a connection string name, or choose the default, and choose whether you want the connection string stored in a local secrets file, or in Azure Key Vault.
The Summary of changes screen shows all the modifications that will be made to your project if you complete the process. If the changes look OK, choose Finish.
If prompted to set a firewall rules, choose Yes.
The connection appears under the Service Dependencies section of the Connected Services tab.