Skip to content

Commit 11b5d3e

Browse files
committed
fixes and touchups
1 parent 973d4c4 commit 11b5d3e

File tree

1 file changed

+35
-32
lines changed

1 file changed

+35
-32
lines changed

articles/app-service/app-service-web-tutorial-dotnet-sqldatabase.md

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ In this tutorial, you:
2525
> - Publish a data-driven web app to Azure.
2626
> - Create an Azure SQL database to hold the app data.
2727
> - Connect the ASP.NET app to the Azure SQL database.
28+
> - Configure a managed identity and Microsoft Entra ID authentication for the database connection.
2829
> - Update the data model and redeploy the app.
2930
> - Stream application logs from Azure to Visual Studio.
3031
@@ -33,7 +34,7 @@ In this tutorial, you:
3334
- [!INCLUDE [quickstarts-free-trial-note](~/reusable-content/ce-skilling/azure/includes/quickstarts-free-trial-note.md)]
3435
- Install <a href="https://www.visualstudio.com/downloads/" target="_blank">Visual Studio 2022</a> with the **ASP.NET and web development** and **Azure development** workloads.
3536
- You can add the workloads to an existing Visual Studio installation by selecting **Get Tools and Features** in the Visual Studio **Tools** menu.
36-
- Make sure you have the latest version of Visual Studio by selecting **Help** > **Check for updates** and installing the latest version if necessary.
37+
- Make sure you have the latest updates for Visual Studio 2022 by selecting **Help** > **Check for updates** and installing the latest version if necessary.
3738

3839
## Create and run the app
3940

@@ -139,31 +140,31 @@ Before you can create a database, you need a [logical SQL server](/azure/azure-s
139140

140141
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.
141142

142-
![Screenshot of the screen with messagea about configuring managed identity for the connection to work.](./media/app-service-web-tutorial-dotnet-sqldatabase/connect-warning.png)
143-
144143
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*.
145144

146145
> [!NOTE]
147146
> If you see **Local user secrets files** instead, make sure you used the **Publish** page, not the **Connected Services** page, to configure SQL Database.
148147
149148
1. Select **Additional settings**, make sure **Azure App Settings** is selected, and select **Finish**.
150149

150+
![Screenshot of the screen with messagea about configuring managed identity for the connection to work.](./media/app-service-web-tutorial-dotnet-sqldatabase/connect-warning.png)
151+
151152
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.
152153

153154
You now need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work.
154155

155156
## Configure managed identity
156157

157-
When the Azure SQL Database creation wizard set up the Azure SQL server with a managed identity and Entra ID Default authentication, it added your Entra ID account as the Azure SQL admin. If you're signed in to the same account in Visual Studio, you can use the same `Authentication=Active Directory Default` connection string to connect to the database in both Visual Studio and Azure.
158+
When the Azure SQL Database creation wizard set up the Azure SQL server with a managed identity and Entra ID Default authentication, it added your Entra ID account as the Azure SQL admin. If you're signed in to the same account in Visual Studio, you can use the same connection string to connect to the database in both Visual Studio and Azure.
158159

159160
1. From the **Tools** menu, select **NuGet Package Manager** > **Package Manager Console**.
160161

161162
1. In the **Package Manager Console**, install the following packages:
162163

163-
```powershell
164-
Install-Package Microsoft.Data.SqlClient
165-
Install-Package Microsoft.EntityFramework.SqlServer
166-
```
164+
```powershell
165+
Install-Package Microsoft.Data.SqlClient
166+
Install-Package Microsoft.EntityFramework.SqlServer
167+
```
167168

168169
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.
169170

@@ -173,15 +174,15 @@ Install-Package Microsoft.EntityFramework.SqlServer
173174

174175
1. At the SQL prompt, run the following commands to grant the minimum permissions your app needs, replacing `<app-name>` with your app name.
175176

176-
```sql
177-
CREATE USER [DotNetAppSqlDb20250604144735] FROM EXTERNAL PROVIDER;
178-
ALTER ROLE db_datareader ADD MEMBER [DotNetAppSqlDb20250604144735];
179-
ALTER ROLE db_datawriter ADD MEMBER [DotNetAppSqlDb20250604144735];
180-
ALTER ROLE db_ddladmin ADD MEMBER [DotNetAppSqlDb20250604144735];
181-
GO
182-
```
177+
```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];
182+
GO
183+
```
183184

184-
1. In *web.config*, remove the `entityFramework/providers/provider` section and line: `<provider invariantName="System.Data.SqlClient" .../>`
185+
1. In *web.config*, remove the `entityFramework/providers/provider` section and line: `<provider invariantName="System.Data.SqlClient" .../>`.
185186

186187
1. In *Models/MyDatabaseContext.cs*, add the following class:
187188

@@ -203,18 +204,7 @@ GO
203204
[DbConfigurationType(typeof(AppServiceConfiguration))]
204205
```
205206

206-
### Allow client connection from your computer
207-
208-
By default, the Azure server allows connections to its databases only from Azure services, such as your Azure app. The new database opened its firewall to the App Service app you created.
209-
210-
To access the database from your local computer, such as from Visual Studio, the Azure server must open the firewall to allow access for the machine's public IP address.
211-
212-
If prompted to add access for your local client IP address, make sure to select the option to **Allow your computer's public IP address**. This option creates a firewall rule to allow the public IP address of your local computer. The dialog box is already populated with your computer's current IP address.
213-
214-
>[!NOTE]
215-
>If your internet service provider changes your public IP address, you need to reconfigure the firewall to access the Azure database again.
216-
217-
### Deploy the ASP.NET app
207+
## Deploy the ASP.NET app
218208

219209
1. At the top of the **Publish** tab, select **Publish**. Your ASP.NET app deploys to Azure, and your default browser launches to the URL of the deployed app.
220210

@@ -228,7 +218,20 @@ Congratulations! Your data-driven ASP.NET application is running live in Azure A
228218

229219
You can use Visual Studio **SQL Server Object Explorer** to easily explore and manage your Azure SQL database. In **SQL Server Object Explorer**, you can perform most common database operations, such as running queries or creating tables, views, and stored procedures.
230220

231-
### Connect to the database locally
221+
### Allow client connection from your computer
222+
223+
By default, the Azure server allows connections to its databases only from Azure services, such as your Azure app. The new database opened its firewall to the App Service app you created.
224+
225+
To access the database from your local computer, such as from Visual Studio, the Azure server must open the firewall to allow access for the machine's public IP address.
226+
227+
If prompted to add access for your local client, make sure to select the option to **Allow your computer's public IP address**. This option creates a firewall rule to allow the public IP address of your local computer. The dialog box is already populated with your computer's current IP address.
228+
229+
If you don't get a prompt to add access for your local computer, you can go to your Azure SQL database in the Azure portal and select **Set server firewall** on the top menu bar. On the **Networking** page under **Firewall rules**, select the option to **Add your client IPv4 address**.
230+
231+
>[!NOTE]
232+
>If your internet service provider changes your public IP address, you need to reconfigure the firewall to access the Azure database again.
233+
234+
### Connect to the Azure SQL database locally
232235

233236
1. From the **View** menu, select **SQL Server Object Explorer**.
234237

@@ -242,7 +245,7 @@ You can use Visual Studio **SQL Server Object Explorer** to easily explore and m
242245

243246
1. Expand **Tables**, right-click the `ToDoes` table, and select **View Data** to interact with the database data.
244247

245-
![Screenshot that shows exploring SQL Database objects.](./media/app-service-web-tutorial-dotnet-sqldatabase/explore-sql-database.png)
248+
![Screenshot that shows exploring SQL Database objects.](./media/app-service-web-tutorial-dotnet-sqldatabase/explore-sql-database.png)
246249

247250
## Update the app with Code First Migrations
248251

@@ -357,7 +360,7 @@ Now that you enabled Code First Migrations in your Azure app, publish your code
357360
358361
1. In the published web app, try adding more to-do items again and selecting **Done**, and they should appear on your home page as completed items.
359362
360-
All your existing to-do items are still displayed. When you republish your ASP.NET application, existing data in your SQL Database isn't lost. Also, Code First Migrations only changes the data schema and leaves your data intact.
363+
All your existing to-do items are still displayed. When you republish your ASP.NET application, existing data in your Azure SQL database isn't lost. Also, Code First Migrations only changes the data schema and leaves your data intact.
361364
362365
![Screenshot that shows the Azure app after Code First Migration.](./media/app-service-web-tutorial-dotnet-sqldatabase/this-one-is-done.png)
363366
@@ -414,7 +417,7 @@ To stop the log-streaming service, select the **Stop monitoring** icon in the **
414417
- [Configure an ASP.NET app for Azure App Service](configure-language-dotnet-framework.md)
415418
- [Quickstart: Start using Cost analysis](/azure/cost-management-billing/costs/quick-acm-cost-analysis?WT.mc_id=costmanagementcontent_docsacmhorizontal_-inproduct-learn)
416419

417-
Go to the next tutorial to learn how to use managed identity to improve your Azure SQL Database connection security.
420+
Go to the next tutorial to learn how to use managed identity to improve Azure SQL Database connection security.
418421

419422
> [!div class="nextstepaction"]
420423
> [Tutorial: Connect to SQL Database from App Service without secrets using a managed identity](tutorial-connect-msi-sql-database.md)

0 commit comments

Comments
 (0)