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
- Install <ahref="https://www.visualstudio.com/downloads/"target="_blank">Visual Studio 2022</a> with the **ASP.NET and web development** and **Azure development** workloads.
35
36
- 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.
37
38
38
39
## Create and run the app
39
40
@@ -139,31 +140,31 @@ Before you can create a database, you need a [logical SQL server](/azure/azure-s
139
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.
141
142
142
-

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

151
+
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.
152
153
153
154
You now need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work.
154
155
155
156
## Configure managed identity
156
157
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.
158
159
159
160
1. From the **Tools** menu, select **NuGet Package Manager** > **Package Manager Console**.
160
161
161
162
1. In the **Package Manager Console**, install the following packages:
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.
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
218
208
219
209
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.
220
210
@@ -228,7 +218,20 @@ Congratulations! Your data-driven ASP.NET application is running live in Azure A
228
218
229
219
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.
230
220
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
232
235
233
236
1. From the **View** menu, select **SQL Server Object Explorer**.
234
237
@@ -242,7 +245,7 @@ You can use Visual Studio **SQL Server Object Explorer** to easily explore and m
242
245
243
246
1. Expand **Tables**, right-click the `ToDoes` table, and select **View Data** to interact with the database data.
244
247
245
-

248
+

246
249
247
250
## Update the app with Code First Migrations
248
251
@@ -357,7 +360,7 @@ Now that you enabled Code First Migrations in your Azure app, publish your code
357
360
358
361
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.
359
362
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.
361
364
362
365

363
366
@@ -414,7 +417,7 @@ To stop the log-streaming service, select the **Stop monitoring** icon in the **
414
417
-[Configure an ASP.NET app for Azure App Service](configure-language-dotnet-framework.md)
415
418
-[Quickstart: Start using Cost analysis](/azure/cost-management-billing/costs/quick-acm-cost-analysis?WT.mc_id=costmanagementcontent_docsacmhorizontal_-inproduct-learn)
416
419
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.
418
421
419
422
> [!div class="nextstepaction"]
420
423
> [Tutorial: Connect to SQL Database from App Service without secrets using a managed identity](tutorial-connect-msi-sql-database.md)
0 commit comments