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
@@ -136,22 +136,14 @@ Before you can create a database, you need a [logical SQL server](/azure/azure-s
136
136
137
137
1. When the database resources are created, select **Next**.
138
138
139
-
### Connect the database
139
+
1. On the **Connect to Azure SQL Database** screen, select **Finish**.
140
140
141
-
The app uses a database context to connect with the database. The database context in this sample is a connection string named `MyDbConnection`. The connection string is set in the *Web.config* file and referenced in the *Models/MyDatabaseContext.cs* file. The Azure app uses the connection string name to connect to the Azure SQL database.
142
-
143
-
1. On the **Connect to Azure SQL Database** screen, under **Connection string name**, enter the name of the connection string referenced in *Models/MyDatabaseContext.cs*, in this case *MyDbConnection*.
141
+

144
142
145
143
> [!NOTE]
146
144
> If you see **Local user secrets files** instead, make sure you used the **Publish** page, not the **Connected Services** page, to configure SQL Database.
147
145
148
-
1. Select **Additional settings**, make sure **Azure App Settings** is selected, and select **Finish**.
149
-
150
-

151
-
152
-
Your app is connected to Azure SQL Database using Managed Identity for Azure services, a secure method of connecting your app to your Azure resources that doesn't use secrets or passwords.
153
-
154
-
You now need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work.
146
+
Your Azure SQL Database connection is now set up to use Managed Identity for Azure services, a secure method of connecting your app to your Azure resources that doesn't use secrets or passwords. You now need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work.
155
147
156
148
## Configure managed identity
157
149
@@ -166,22 +158,31 @@ When the Azure SQL Database creation wizard set up the Azure SQL server with a m
1. In a PowerShell command line, run the following command to sign in to SQL Database, replacing `<server-name>` with your server name, `<db-name>` with your database name, and `<entra-id-user>` with your Microsoft Entra user name.
161
+
1. In a PowerShell command line, run the following command to sign in to SQL Database, replacing `<server-name>` with your server nameand `<entra-id-user>` with the Microsoft Entra user name you used to set up the database in Visual Studio. That Entra user has admin access to the database server by default.
1. At the SQL prompt, run the following commands to grant the minimum permissions your app needs, replacing `<app-name>` with your app name.
176
169
177
170
```sql
178
-
CREATE USER [DotNetAppSqlDb20250604144735] FROM EXTERNAL PROVIDER;
179
-
ALTER ROLE db_datareader ADD MEMBER [DotNetAppSqlDb20250604144735];
180
-
ALTER ROLE db_datawriter ADD MEMBER [DotNetAppSqlDb20250604144735];
181
-
ALTER ROLE db_ddladmin ADD MEMBER [DotNetAppSqlDb20250604144735];
171
+
CREATE USER [<app-name>] FROM EXTERNAL PROVIDER;
172
+
ALTER ROLE db_datareader ADD MEMBER [<app-name>];
173
+
ALTER ROLE db_datawriter ADD MEMBER [<app-name>];
174
+
ALTER ROLE db_ddladmin ADD MEMBER [<app-name>];
182
175
GO
183
176
```
184
177
178
+
## Update the database context
179
+
180
+
The app uses a database context to connect with the database, which is referenced in the *Models/MyDatabaseContext.cs* file. In this section, you update the code to refer to the Entity Framework 6 SQL Server provider, which depends on the modern [Microsoft.Data.SqlClient](https://github.com/dotnet/SqlClient) ADO.NET provider.
181
+
182
+
The Entity Framework 6 provider replaces the built-in `System.Data.SqlClient` SQL Server provider, and includes support for Microsoft Entra ID authentication methods. For more information, see [Microsoft.EntityFramework.SqlServer}](https://www.nuget.org/packages/Microsoft.EntityFramework.SqlServer).
183
+
184
+
`[DbConfigurationType(typeof(MicrosoftSqlDbConfiguration))]` works locally to use `Microsoft.Data.SqlClient` for the database context, but because `System.Data.SqlClient` is hardcoded as the provider in Azure App Service, you need to extend `MicrosoftSqlDbConfiguration` to redirect references to `System.Data.SqlClient` to `Microsoft.Data.SqlClient` instead.
185
+
185
186
1. In *web.config*, remove the `entityFramework/providers/provider` section and line: `<provider invariantName="System.Data.SqlClient" .../>`.
186
187
187
188
1. In *Models/MyDatabaseContext.cs*, add the following class:
0 commit comments