You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/azure/azure-app-insights-add-connected-service.md
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -119,9 +119,16 @@ The connected service functionality adds all the needed references and connectio
119
119
120
120
1. When the **Configure Azure Application Insights** screen is displayed, the new component appears in the list. Select the new component in the list, and select **Next**.
121
121
122
-
1. Enter an instrumentation key name, or choose the default, and choose whether you want the connection string stored in a local secrets file, or in [Azure Key Vault](/azure/key-vault).
122
+
1. Enter a name for the connection setting, and an instrumentation key name, or accept the defaults.
> For improved security, in Visual Studio 17.12 and later, this step creates a connection setting name; previous versions create a connection string. Connection strings stored in the local filesystem can lead to a security risk, if they're inadvertently exposed.
128
+
129
+
1. Click **Additional settings**, and choose whether you want the connection string stored in a local secrets file, or in [Azure Key Vault](/azure/key-vault).
130
+
131
+

125
132
126
133
1. 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**.
Copy file name to clipboardExpand all lines: docs/azure/azure-cache-for-redis-add-connected-service.md
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -127,9 +127,16 @@ The connected service functionality adds all the needed references and connectio
127
127
128
128
1. When the **Configure Azure Cache for Redis** screen is displayed, the new cache appears in the list. Select the new database in the list, and select **Next**.
129
129
130
-
1. 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](/azure/key-vault).
130
+
1. Enter a connection setting name, or accept the default.
131
131
132
-

132
+

133
+
134
+
> [!NOTE]
135
+
> For improved security, in Visual Studio 17.12 and later, this step creates a connection setting name; previous versions create a connection string. Connection strings stored in the local filesystem can lead to a security risk, if they're inadvertently exposed.
136
+
137
+
1. Click on **Additional settings** and choose whether you want the connection setting stored in a local secrets file, or in [Azure Key Vault](/azure/key-vault).
138
+
139
+

133
140
134
141
1. 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**.
Copy file name to clipboardExpand all lines: docs/azure/azure-signalr-add-connected-service.md
+9-2Lines changed: 9 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -118,9 +118,16 @@ The connected service functionality adds all the needed references and connectio
118
118
119
119
1. When the **Configure Azure SignalR Service** screen is displayed, the new instance appears in the list. Select the new instance in the list, and select **Next**.
120
120
121
-
1. 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](/azure/key-vault).
121
+
1. Enter a connection setting name, or accept the default.
> For improved security, in Visual Studio 17.12 and later, this step creates a connection setting name; previous versions create a connection string. Connection strings stored in the local filesystem can lead to a security risk, if they're inadvertently exposed.
127
+
128
+
1. Click on **Additional settings** and choose whether you want the connection information stored in a local secrets file, or in [Azure Key Vault](/azure/key-vault).

124
131
125
132
1. 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**.
Copy file name to clipboardExpand all lines: docs/azure/azure-sql-database-add-connected-service.md
+116-2Lines changed: 116 additions & 2 deletions
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ author: ghogen
5
5
manager: mijacobs
6
6
ms.subservice: azure-development
7
7
ms.topic: conceptual
8
-
ms.date: 05/09/2024
8
+
ms.date: 10/30/2024
9
9
ms.author: ghogen
10
10
monikerRange: ">= vs-2019"
11
11
---
@@ -34,6 +34,97 @@ The connected service functionality adds all the needed references and connectio
34
34
35
35
## Connect to Azure SQL Database using Connected Services
36
36
37
+
:::moniker range=">=vs-2022"
38
+
39
+
1. Open your project in Visual Studio.
40
+
41
+
1. In **Solution Explorer**, right-click the **Connected Services** node, and, from the context menu, select **Add** to open the menu of available services.
42
+
43
+

44
+
45
+
If you don't see the **Connected Services** node, choose **Project** > **Connected Services** > **Add**.
46
+
47
+
1. Choose **SQL Server Database**. The **Connect to dependency** page appears. You should see several options:
48
+
49
+
- SQL Server Express LocalDB, the built-in SQL Database offering installed with Visual Studio
50
+
- SQL Server Database on a local container on your machine
51
+
- SQL Server Database, an on-premises SQL Server on the local network
52
+
- Azure SQL Database, for the SQL Database running as an Azure service
53
+
54
+
You can reduce cost and simplify early development by starting with a local database. You can migrate to the live service in Azure later by repeating these steps and choosing another option. If you create a database locally that you want to re-create in Azure, you can migrate your database to Azure at that time.
If you want to connect to the Azure service, continue to the next step, or if you aren't signed in already, sign in to your Azure account before continuing. If you don't have an Azure account, you can sign up for a [free trial](https://azure.microsoft.com/free/).
59
+
60
+
1. In the **Configure Azure SQL Database** screen, select an existing Azure SQL Database, and select **Next**.
61
+
62
+
If you need to create a new component, go to the next step. Otherwise, skip to step 7.
63
+
64
+

65
+
66
+
1. To create an Azure SQL database:
67
+
68
+
1. Select **Create New** by the green plus sign.
69
+
70
+
1. Fill out the **Azure SQL Database: Create new** screen, and select **Create**.
71
+
72
+

73
+
74
+
1. 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**.
75
+
76
+
1. Enter a connection string name, or choose the default, and then choose **Additional Settings**.
> With Visual Studio 2022 version 17.12 and later, this procedure uses Microsoft Entra managed identity, a passwordless authentication method, to connect to the database. The warning on this screen means that you need to perform a manual step in the Azure Portal after completing this procedure in Visual Studio. See [Microsoft Entra authentication](#microsoft-entra-authentication).
82
+
83
+
1. Choose whether you want the connection string stored in a local secrets file, or in [Azure Key Vault](/azure/key-vault), and then choose **Next**.
84
+
85
+

86
+
87
+
1. 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**.
88
+
89
+

90
+
91
+
If prompted to set a firewall rules, choose **Yes**.
1. In Solution Explorer, double-click on the **Connected Services** node to open the **Connected Services** tab. The connection appears under the **Service Dependencies** section:
If you click on the three dots next to the dependency you added, you can see various options such as **Connect** to reopen the wizard and change the connection. You can also click the three dots at the top right of the window to see options to start local dependencies, change settings, and more.
100
+
101
+
1. If you're using managed identity (Visual Studio 17.12 and later), see the next section to set up the managed identity user in your Azure SQL database.
102
+
103
+
## Microsoft Entra authentication
104
+
105
+
With Visual Studio 2022 version 17.12 and later, the connected services procedure uses Microsoft Entra authentication, which is the most secure method of authentication. However, Visual Studio doesn't create the Microsoft Entra admin user on the Azure SQL database for you automatically. If there isn't a Microsoft Entra admin user, the connection will fail to authenticate successfully.
106
+
107
+
You can use the Azure Portal, PowerShell, or the Azure CLI to create the Microsoft Entra admin user. For detailed instructions for each of these methods, see [Set the Microsoft Entra admin user](/azure/azure-sql/database/authentication-aad-configure?view=azuresql&preserve-view=true&tabs=azure-portal#azure-sql-database-and-azure-synapse-analytics).
108
+
109
+
After completing the Connected Services process, you'll need to create a SQL user that corresponds to the managed identity, and set permissions by executing SQL statements in the database. Sign in to the [query editor](/azure/azure-sql/database/connect-query-portal?view=azuresql&preserve-view=true) in the Azure Portal as your Microsoft Entra admin user, and execute statements like the following:
110
+
111
+
```tsql
112
+
CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;
113
+
ALTER ROLE db_datareader ADD MEMBER [<identity-name>];
114
+
ALTER ROLE db_datawriter ADD MEMBER [<identity-name>];
115
+
ALTER ROLE db_ddladmin ADD MEMBER [<identity-name>];
116
+
117
+
GO
118
+
```
119
+
120
+
The `<identity-name>` is the name of the managed identity in Microsoft Entra ID. If the identity is system-assigned, the name is always the same as the name of your App Service app. For a deployment slot, the name of its system-assigned identity is `<app-name>/slots/<slot-name>`. To grant permissions for a Microsoft Entra group, use the group's display name instead (for example, `myAzureSQLDBAccessGroup`). See [Managed Identity types](/entra/identity/managed-identities-azure-resources/overview#managed-identity-types) and [Managed identities in Microsoft Entra for Azure SQL](/azure/azure-sql/database/authentication-azure-ad-user-assigned-managed-identity?view=azuresql&preserve-view=true). The roles that you add depend on your use cases. See [ALTER ROLE](/sql/t-sql/statements/alter-role-transact-sql?view=azuresqldb-current&preserve-view=true).
121
+
122
+
If your code references `System.Data.SqlClient`, you'll need to upgrade to `Microsoft.Data.SqlClient`, since `System.Data.SqlClient` doesn't support Microsoft Entra authentication. To upgrade, add a reference the [Microsoft.Data.SqlClient NuGet package](https://www.nuget.org/packages/Microsoft.Data.SqlClient), and update any using directives that reference `System.Data.SqlClient` to reference the `Microsoft.Data.SqlClient` namespace. There are some behavior changes; see [Porting cheat sheet](https://github.com/dotnet/SqlClient/blob/main/porting-cheat-sheet.md).
123
+
124
+
:::moniker-end
125
+
126
+
:::moniker range="<=vs-2019"
127
+
37
128
1. Open your project in Visual Studio.
38
129
39
130
1. In **Solution Explorer**, right-click the **Connected Services** node, and, from the context menu, select **Add** to open the menu of available services.
@@ -89,6 +180,8 @@ The connected service functionality adds all the needed references and connectio
89
180
90
181
If you click on the three dots next to the dependency you added, you can see various options such as **Connect** to reopen the wizard and change the connection. You can also click the three dots at the top right of the window to see options to start local dependencies, change settings, and more.
91
182
183
+
:::moniker-end
184
+
92
185
## Access the connection string
93
186
94
187
Learn how to store secrets safely by following [Safe storage of app secrets in development in ASP.NET Core](/aspnet/core/security/app-secrets?tabs=windows). In particular, to read the connection string from the secrets store, you can add code as in [Read the secret via the configuration API](/aspnet/core/security/app-secrets?tabs=windows#read-the-secret-via-the-configuration-api). See also [Dependency injection in ASP.NET Core](/aspnet/core/fundamentals/dependency-injection).
@@ -142,12 +235,33 @@ For convenience, this command lets you jump to the SQL Server Object Explorer, s
142
235
143
236
You can continue with the quickstarts for Azure SQL Database, but instead of starting from the beginning, you can start after the initial connection is set up. If you're using Entity Framework, you can start at [Add the code to connect to Azure SQL Database](/azure/azure-sql/database/azure-sql-dotnet-entity-framework-core-quickstart?view=azuresql&preserve-view=true&tabs=visual-studio%2Cservice-connector%2Cportal#add-the-code-to-connect-to-azure-sql-database). If you're using `SqlClient` or ADO.NET data classes, you can start at [Add the code to connect to Azure SQL Database](/azure/azure-sql/database/azure-sql-dotnet-quickstart?view=azuresql&preserve-view=true&tabs=visual-studio%2Cpasswordless%2Cservice-connector%2Cportal#add-the-code-to-connect-to-azure-sql-database).
144
237
145
-
Your code won't exactly match what is used in the quickstarts, which use a different way of getting the connection string. The connection strings are secrets and are securely stored as explained in [Safe storage of app secrets in development in ASP.NET Core](/aspnet/core/security/app-secrets?tabs=windows). In particular, to read the connection string from the secrets store, you can add code as in [Read the secret via the configuration API](/aspnet/core/security/app-secrets?tabs=windows#read-the-secret-via-the-configuration-api). In ASP.NET Core projects, the connection string created by Connected Services is available in a configuration object. You can access it by a property on the `WebApplicationBuilder` class (`builder` in many project templates), as in the following example:
238
+
Your code won't exactly match what is used in the quickstarts, which use a different way of getting the connection string. The connection strings are secrets and are securely stored as explained in [Safe storage of app secrets in development in ASP.NET Core](/aspnet/core/security/app-secrets?tabs=windows). In particular, to read the connection string from the secrets store, you can add code as in [Read the secret via the configuration API](/aspnet/core/security/app-secrets?tabs=windows#read-the-secret-via-the-configuration-api).
239
+
240
+
:::moniker range=">=vs-2022"
241
+
In ASP.NET Core projects, the connection setting or connection string created by Connected Services is available in a configuration object. You can access it by a property on the `WebApplicationBuilder` class (`builder` in many project templates), as in the following example:
The string to provide to the Configuration property should match the key in *secrets.json* or in Azure Key Vault, which you provided in the Connected Services procedure. For example, with Visual Studio 2022 17.12 and later, the connection setting is stored in *secrets.json* as:
In ASP.NET Core projects, the connection setting or connection string created by Connected Services is available in a configuration object. You can access it by a property on the `WebApplicationBuilder` class (`builder` in many project templates), as in the following example:
146
258
147
259
```csharp
148
260
var connection = builder.Configuration["ConnectionStrings:ConnectionString1"];
0 commit comments