Skip to content

Commit 1ef62fd

Browse files
Merge pull request #10464 from MicrosoftDocs/main638660024254539228sync_temp
For protected branch, push strategy should use PR and merge to target branch method to work around git push error
2 parents a593f5a + 8670d4e commit 1ef62fd

File tree

56 files changed

+689
-157
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+689
-157
lines changed

.github/policies/auto-merge.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ configuration:
1616
label: ':octocat: auto-merge'
1717
- targetsBranch:
1818
branch: live
19+
- isActivitySender:
20+
user: microsoft-github-policy-service[bot]
1921
then:
2022
- enableAutoMerge:
2123
mergeMethod: Merge
@@ -26,4 +28,4 @@ configuration:
2628
- labelRemoved:
2729
label: ':octocat: auto-merge'
2830
then:
29-
- disableAutoMerge
31+
- disableAutoMerge

.github/policies/scheduled-pr.yml

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,32 @@ where:
66
configuration:
77
resourceManagementConfiguration:
88
scheduledSearches:
9-
- description: Push to live branch (scheduled publish)
9+
- description: Push to live branch (scheduled 10 AM publish)
10+
frequencies:
11+
- daily:
12+
time: 17:00
13+
filters: []
14+
actions:
15+
- createPullRequest:
16+
head: main
17+
base: live
18+
title: Merge main into live
19+
body: Please don't squash-merge this PR.
20+
- description: Push to live branch (scheduled publish 5 PM)
1021
frequencies:
1122
- daily:
1223
time: 1:00
24+
filters: []
25+
actions:
26+
- createPullRequest:
27+
head: main
28+
base: live
29+
title: Merge main into live
30+
body: Please don't squash-merge this PR.
31+
- description: Push to live branch (scheduled publish 1 AM)
32+
frequencies:
1333
- daily:
1434
time: 9:00
15-
- daily:
16-
time: 17:00
1735
filters: []
1836
actions:
1937
- createPullRequest:

docs/azure/azure-app-insights-add-connected-service.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,9 +119,16 @@ The connected service functionality adds all the needed references and connectio
119119

120120
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**.
121121

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.
123123

124-
![Screenshot showing "Specify connection string" screen.](./media/azure-app-insights-add-connected-service/connection-string.png)
124+
![Screenshot showing "Provide connection configuration settings" screen.](./media/vs-2022/connect-to-application-insights-connection-setting.png)
125+
126+
> [!NOTE]
127+
> 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+
![Screenshot showing Connect to Application Insights - additional settings screen.](./media/vs-2022/connect-to-application-insights-additional-settings.png)
125132

126133
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**.
127134

docs/azure/azure-cache-for-redis-add-connected-service.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,9 +127,16 @@ The connected service functionality adds all the needed references and connectio
127127

128128
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**.
129129

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.
131131

132-
![Screenshot of the Azure Cache for Redis connection information page. Next is highlighted.](./media/azure-redis-cache-add-connected-service/connection-string.png)
132+
![Screenshot of the Azure Cache for Redis connection information page. Next is highlighted.](./media/vs-2022/connect-to-azure-cache-for-redis.png)
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+
![Screenshot of the Azure Cache for Redis additional settings page.](./media/vs-2022/connect-to-azure-cache-additional-settings.png)
133140

134141
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**.
135142

docs/azure/azure-signalr-add-connected-service.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,16 @@ The connected service functionality adds all the needed references and connectio
118118

119119
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**.
120120

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.
122+
123+
![Screenshot showing "Specify connection string" screen.](./media/vs-2022/azure-signalr-configuration-setting.png)
124+
125+
> [!NOTE]
126+
> 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).
122129

123-
![Screenshot showing "Specify connection string" screen.](./media/azure-signalr-add-connected-service/connection-string.png)
130+
![Screenshot showing additional settings with options for storing the connection setting.](./media/vs-2022/azure-signalr-additional-settings.png)
124131

125132
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**.
126133

docs/azure/azure-sql-database-add-connected-service.md

Lines changed: 116 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ author: ghogen
55
manager: mijacobs
66
ms.subservice: azure-development
77
ms.topic: conceptual
8-
ms.date: 05/09/2024
8+
ms.date: 10/30/2024
99
ms.author: ghogen
1010
monikerRange: ">= vs-2019"
1111
---
@@ -34,6 +34,97 @@ The connected service functionality adds all the needed references and connectio
3434

3535
## Connect to Azure SQL Database using Connected Services
3636

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+
![Screenshot showing Connected Services context menu options.](./media/vs-2022/add-connected-service-context-menu-2.png)
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.
55+
56+
![Screenshot showing SQL Database choices.](./media/vs-2022/sql-database-choices-2.png)
57+
58+
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+
![Screenshot showing "Connect to existing Azure SQL Database component" screen.](./media/azure-sql-database-add-connected-service/created-azure-sql-database.png)
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+
![Screenshot showing "New Azure SQL database" screen.](./media/azure-sql-database-add-connected-service/create-new-azure-sql-database.png)
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**.
77+
78+
![Screenshot showing "Specify connection string" screen.](./media/vs-2022/connect-to-azure-sql-database-light.png)
79+
80+
> [!NOTE]
81+
> 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+
![Screenshot showing the options for where to store the Azure SQL Database connection string.](media/vs-2022/connect-to-azure-sql-database-options-light.png)
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+
![Screenshot showing "Summary of changes" section.](./media/vs-2022/connect-to-azure-sql-database-summary-light.png)
90+
91+
If prompted to set a firewall rules, choose **Yes**.
92+
93+
![Screenshot showing firewall rules.](./media/azure-sql-database-add-connected-service/firewall-rules.png)
94+
95+
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:
96+
97+
![Screenshot showing "Service Dependencies" section.](./media/azure-sql-database-add-connected-service/service-dependencies-after.png)
98+
99+
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+
37128
1. Open your project in Visual Studio.
38129

39130
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
89180

90181
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.
91182

183+
:::moniker-end
184+
92185
## Access the connection string
93186

94187
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
142235

143236
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).
144237

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:
242+
243+
```csharp
244+
var connection = builder.Configuration["ConnectionStrings:DatabaseConnection"];
245+
```
246+
247+
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:
248+
249+
```json
250+
{
251+
"ConnectionStrings:DatabaseConnection": "Server=tcp:webapplication16dbserver.database.windows.net;Authentication=Active Directory Default;Database=WebApplication16_db;",
252+
}
253+
:::moniker-end
254+
255+
:::moniker range="<=vs-2019"
256+
257+
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:
146258

147259
```csharp
148260
var connection = builder.Configuration["ConnectionStrings:ConnectionString1"];
149261
```
150262

263+
:::moniker-end
264+
151265
## Related content
152266

153267
- [Azure SQL Database product page](https://azure.microsoft.com/services/sql-database/)
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

0 commit comments

Comments
 (0)