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
Copy file name to clipboardExpand all lines: articles/app-service/tutorial-dotnetcore-sqldb-app.md
+9-7Lines changed: 9 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -174,7 +174,7 @@ To see the entirety of the command output, drop the `--query` in the command.
174
174
175
175
## 5 - Generate the Database Schema
176
176
177
-
To generate our database schema, set up a firewall rule on the SQL database server. This rule lets your local computer connect to Azure. For this step, you'll need to know your local computer's IP address. For more information about how to find the IP address, [see here](https://whatismyipaddress.com/).
177
+
To generate our database schema, set up a firewall rule on the SQL database server. This rule lets your local computer connect to Azure. For this step, you'll need to know your local computer's IP address. Azure will attempt to detect your IP automatically and presents the option to add it for you, as seen in the steps below. For more information about how to find your IP address manually, [see here](https://whatismyipaddress.com/).
178
178
179
179
### [Azure portal](#tab/azure-portal)
180
180
@@ -195,26 +195,28 @@ az sql server firewall-rule create --resource-group msdocs-core-sql --server <yo
195
195
196
196
---
197
197
198
-
Next, update the *appsettings.json* file in the sample project with the [connection string Azure SQL Database](#4---connect-the-app-to-the-database). The update allows us to run migrations locally against our database hosted in Azure. Replace the username and password placeholders with the values you chose when creating your database.
198
+
Next, update the name of the connection string in `appsettings.json` file to match the`AZURE_SQL_CONNECTION` name generated by the service connector. When the app is deployed to Azure, the `localdb` connection string value will be overridden by the connection string stored in Azure.
Next, update the *Startup.cs* file the sample project by updating the existing connection string name `MyDbConnection` to `AZURE_SQL_CONNECTIONSTRING`:
206
+
Next, update the `Startup.cs` file the sample project by updating the existing connection string name `MyDbConnection` to `AZURE_SQL_CONNECTIONSTRING`. This change configures the `DbContext` to use the correct connection string in Azure and locally from the `appsettings.json` file.
From a local terminal, run the following commands to install the necessary CLI tools for Entity Framework Core, create an initial database migration file, and apply those changes to update the database:
213
+
From a local terminal, run the following commands to install the necessary CLI tools for Entity Framework Core, create an initial database migration file, and apply those changes to update the database. Make sure to pass in the connection string value you copied from the Azure SQL database for the `connection` parameter. The `connection` parameter overrides the value of the connection string that is configured for the `DbContext` in the `startup.cs` file.
212
214
213
215
```dotnetcli
214
216
cd <sample-root>\DotNetCoreSqlDb
215
217
dotnet tool install -g dotnet-ef
216
218
dotnet ef migrations add InitialCreate
217
-
dotnet ef database update
219
+
dotnet ef database update --connection "<your-azure-sql-connection-string>"
218
220
```
219
221
220
222
After the migration finishes, the correct schema is created.
@@ -223,7 +225,7 @@ If you receive the error `Client with IP address xxx.xxx.xxx.xxx is not allowed
223
225
224
226
## 6 - Deploy to the App Service
225
227
226
-
That we're able to create the schema in the database means that our .NET app can connect to the Azure database successfully with the new connection string. Remember that the service connector already configured the `AZURE_SQL_CONNECTIONSTRING` connection string in our App Service app. We're now ready to deploy our .NET app to the App Service.
228
+
That we're able to create the schema in the database means that our .NET app can connect to the Azure database successfully with the new connection string. Remember that the service connector already configured the `AZURE_SQL_CONNECTIONSTRING` connection string in our App Service app. We're now ready to deploy our .NET app to the App Service. When the app is deployed, the `AZURE_SQL_CONNECTION` configuration applied to the App Service by the Service Connector will override the `localdb` connection string with the same name in the `appsettings.json` file.
227
229
228
230
### [Deploy using Visual Studio](#tab/visualstudio-deploy)
0 commit comments