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. You can add the workloads to an existing Visual Studio installation by selecting **Get Tools and Features** in the Visual Studio **Tools** menu.
34
+
- 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
+
- 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.
35
37
36
38
## Create and run the app
37
39
@@ -56,8 +58,6 @@ The sample project contains a basic [ASP.NET MVC](https://www.asp.net/mvc) creat
56
58
57
59
To publish the app to Azure, you create and configure a Publish profile that has an Azure App Service and App Service Plan to host the app. You then create an Azure SQL Server and Azure SQL database to contain the app data, and configure a database context to connect the app with the database.
58
60
59
-
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.
60
-
61
61
1. In Visual Studio **Solution Explorer**, right-click the **DotNetAppSqlDb** project and select **Publish**.
62
62
63
63

@@ -125,30 +125,23 @@ Before you can create a database, you need a [logical SQL server](/azure/azure-s
125
125
126
126
1. Change the server name to a value you want. The server name must be unique across all servers in Azure SQL.
127
127
128
-
1. Add an administrator username and password. For password requirements, see [Password policy](/sql/relational-databases/security/password-policy).
129
-
130
-
Remember this username and password. You need them to manage the server later.
128
+
1. Select **OK**.
131
129
132
130

133
131
134
-
> [!IMPORTANT]
135
-
> Your password in the connection strings is masked in both Visual Studio and App Service, but maintaining it still adds to the attack surface of your app. App Service can use [managed service identities](overview-managed-identity.md) to eliminate this risk by removing the need to maintain secrets in your code or app configuration. For more information, see [Tutorial: Connect to SQL Database from App Service without secrets using a managed identity](tutorial-connect-msi-sql-database.md).
136
-
137
-
1. Select **OK**.
138
-
139
132
1. On the **Azure SQL Database** screen, keep the default generated **Database Name**. Select **Create** and wait for the database resources to be created.
140
133
141
134

142
135
136
+
1. When the database resources are created, select **Next**.
137
+
143
138
### Connect the database
144
139
145
140
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.
146
141
147
-
1. When the database resources are created, select **Next**.
148
-
149
142

150
143
151
-
1.Under**Connection string name**, enter the name of the connection string referenced in *Models/MyDatabaseContext.cs*, in this case *MyDbConnection*.
144
+
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*.
152
145
153
146
> [!NOTE]
154
147
> If you see **Local user secrets files** instead, make sure you used the **Publish** page, not the **Connected Services** page, to configure SQL Database.
@@ -157,11 +150,73 @@ The app uses a database context to connect with the database. The database conte
157
150
158
151
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.
159
152
160
-
Note the message that you need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work. For more information, see [Grant permissions to managed identity](tutorial-connect-msi-sql-database.md#grant-permissions-to-managed-identity).
153
+
You now need to set the appropriate permissions on the SQL user corresponding with this managed identity for the connection to work.
154
+
155
+
## Configure managed identity
156
+
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
+
159
+
1. From the **Tools** menu, select **NuGet Package Manager** > **Package Manager Console**.
160
+
161
+
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.
161
216
162
217
### Deploy the ASP.NET app
163
218
164
-
1.When the connection succeeds, 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.
219
+
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.
165
220
166
221
1. To test the app, add a few to-do items.
167
222
@@ -189,17 +244,6 @@ You can use Visual Studio **SQL Server Object Explorer** to easily explore and m
189
244
190
245

191
246
192
-
### Allow client connection from your computer
193
-
194
-
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.
195
-
196
-
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.
197
-
198
-
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.
199
-
200
-
>[!NOTE]
201
-
>If your internet service provider changes your public IP address, you need to reconfigure the firewall to access the Azure database again.
202
-
203
247
## Update the app with Code First Migrations
204
248
205
249
You can use familiar tools in Visual Studio to update your database and app in Azure. In this step, you use Code First Migrations in Entity Framework to change your database schema and publish the change to Azure.
@@ -291,15 +335,15 @@ Make some changes in your code to see the `Done` property in action. For this tu
291
335
292
336
### Enable Code First Migrations in Azure
293
337
294
-
Now that your code change works, including database migration, you can publish it to your Azure app and update your SQL Database with Code First Migrations too.
338
+
Now that your code change works, including database migration, you can publish it to your Azure app and update your Azure SQL database with Code First Migrations too.
295
339
296
340
1. In Visual Studio **Solution Explorer**, right-click your project and select **Publish**.
297
341
298
342
1. Select **More actions** > **Edit** to open the publish settings.
299
343
300
344

301
345
302
-
1. In the **MyDatabaseContext** dropdown, select the database connection for your Azure SQL Database.
346
+
1. In the **MyDatabaseContext** dropdown, select the database connection for your Azure SQL database.
303
347
304
348
1. Select **Execute Code First Migrations (runs on application start)**, and then select **Save**.
0 commit comments