Skip to content

Latest commit

 

History

History
50 lines (34 loc) · 2.42 KB

powershell-connect-to-sql.md

File metadata and controls

50 lines (34 loc) · 2.42 KB
title description tags ms.assetid ms.topic ms.date ms.custom
PowerShell: Connect to SQL Database
Learn how to use Azure PowerShell to automate deployment and management of App Service. This sample shows how to connect an app to a SQL Database.
azure-service-management
055440a9-fff1-49b2-b964-9c95b364e533
sample
12/06/2022
mvc, devx-track-azurepowershell

Connect an App Service app to SQL Database

In this scenario you will learn how to create a database in Azure SQL Database and an App Service app. Then you will link the database to the app using app settings.

If needed, install the Azure PowerShell using the instruction found in the Azure PowerShell guide, and then run Connect-AzAccount to create a connection with Azure.

Sample script

[!INCLUDE updated-for-az]

[!code-azurepowershell-interactivemain]

Clean up deployment

After the script sample has been run, the following command can be used to remove the resource group, App Service app, and all related resources.

Remove-AzResourceGroup -Name myResourceGroup -Force

Script explanation

This script uses the following commands. Each command in the table links to command specific documentation.

Command Notes
New-AzResourceGroup Creates a resource group in which all resources are stored.
New-AzAppServicePlan Creates an App Service plan.
New-AzWebApp Creates an App Service app.
New-AzSQLServer Creates a server.
New-AzSqlServerFirewallRule Creates a server-level firewall rule.
New-AzSQLDatabase Creates a database or an elastic database.
Set-AzWebApp Modifies an App Service app's configuration.

Next steps

For more information on the Azure PowerShell module, see Azure PowerShell documentation.

Additional Azure PowerShell samples for Azure App Service can be found in the Azure PowerShell samples.