This is a documentation showing how to connect an asp.net app service to an azure sql database
to carry out this Project, I used the following tools
- Visual studio 2023
- A to do list app source code written in html , javascript and css.
To connect an asp.net web app to sql database, we will go through the following steps:
Create a new project
- Open visual Studio 2023 and click on new project
- select ASP.net core web app
- click on next
- I named the application MyFirstAzureWebApp, and then selected Next.
- Select .NET 7.0 (Standard-term support).
- Set Authentication to None and create as shown below
- From the Visual Studio menu, select Debug > Start Without Debugging to run the web app locally. If you see a message asking you to trust a self-signed certificate, select Yes.
Publish the app
- look Solution Explorer at the left hand side , right-click the MyFirstAzureWebApp project and select Publish.
- In Publish, select Azure and then Next.
- Choose the Specific target, Azure App Service (Linux) Then, select Next
- To publish your app, you need an account. I signed into my account by clicking on the sign in button to use your Azure subscription.
For Subscription, I select the subscription already listed
since that is the subscription I am usingFor Resource group, I select my resource group gracewebapp
For hosting plan, I clicked on the one with my webapp name
Select Create to create the Azure resources.
Once the wizard completes, the Azure resources are created for you, and you're ready to publish your ASP.NET Core project.
In the Publish dialog, ensure your new App Service app is selected, then select Finish, then select Close. Visual Studio creates a publish profile for you for the selected App Service app.
In the Publish page, select Publish. If you see a warning message, select Continue.
Update the app and redeploy
In Solution Explorer, I open Index.cshtml.
-
I replaced the
element with my html ,css and javascript code as shown belowSave your changes.
To redeploy to Azure, right-click the MyFirstAzureWebApp project in Solution Explorer and select Publish.
In the Publish summary page, select Publish.
After a successful publishing completes, Visual Studio opens a browser with the webapp showing
Manage the Azure app
- Go to Azure portal , then go to appservice, look for the app MyFirstAzureWebApp
- Select the name of the name of the app and the picture below is showed
Connecting to SQL Database
Create an sql database. I already have one from creating a web app + database
Go to your sql database, select connection string
navigate to ADO.net and copy the value
go to the app service you just deployed, navigate to configuration
click on create new connection string
Under name, enter dbconnection
under value, paste the value you just copied form the sqldatabase ado.net.
under type, select sql server.
click on ok
Our app service has ben successfully connected to a Azure SQL database

Top comments (0)