I am creating an azure function to connect to my SQL database using c#. Question #1 How do I make a SQL connection with an azure function.
#2 Step by step guide on how to create such a function
I am creating an azure function to connect to my SQL database using c#. Question #1 How do I make a SQL connection with an azure function.
#2 Step by step guide on how to create such a function
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Ijas AhamedRank #708 · 3.3K reputationPosted Feb 7, 2023, 10:46 PM EST
1. To connect to a SQL database from an Azure Function in C#, you need to use the ADO.NET library to create a connection string and open a connection to the database. Here's an example of how to do this
using (SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["sqlconnectionstring"].ConnectionString)) { connection.Open(); // Perform database operations connection.Close(); }The connection string in the above example is read from the
appsettings.jsonfile, which is stored in the configuration settings for the Azure Function.#2. To create an Azure Function that connects to a SQL database, follow these steps:
Open the Azure portal and create a new Azure Function app.
In the Azure Function app, create a new function using the Azure Functions template.
In the function code, use the ADO.NET library to create a connection string and open a connection to the database, as shown in the example above.
Store the connection string in the configuration settings for the Azure Function.
Deploy the Azure Function app to the cloud.
Test the Azure Function to verify that it can successfully connect to the SQL database.
Note: Before you create an Azure Function, you need to have a SQL database set up and the connection details, such as the server name, database name, username, and password, to connect to it.
Muhammad Imran AnsariRank #326 · 7.6K reputationPosted Feb 9, 2023, 12:13 AM EST
HI Elimelech,
You can follow the below links to connect with SQL in Azure Function:
https://learn.microsoft.com/en-us/azure/mysql/single-server/connect-csharp
Here is the sort of similar contents and step-by-step guide:
https://www.c-sharpcorner.com/article/develop-a-rest-api-with-azure-functions-and-sql/