How to connect to sql database from an azure function c#

Saranya Santhakumaran 1 Reputation point
2021-05-24T18:43:24.09+00:00

Requirement is to read records from sql table and process the record and then put it back to sql . Using azure function for the same .

While trying to connect to SQL database from Azure function after publishing, I am getting an error
"A network - related or instance specific error occurred while establishing a connection to SQL Server The server was not found or was not accessible . verify that the instance name is correct and that SQL Server is configured to allow remote connections ".

While executing locally by giving the connection string in local.setting.json it works fine.

Tried in App settings and also in Connection string of function app setting , getting the above mentioned error.

Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
5,909 questions
SQL Server Other
Developer technologies C#
{count} votes

1 answer

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 27,471 Reputation points Microsoft Employee Moderator
    2021-05-25T18:02:33.667+00:00

    Hello @Saranya Santhakumaran , as your SQL server is on-prem then you will have to use Hybrid connections in your function app instead. As per the documentation just be aware that Hybrid Connections are not supported on consumption plan and require Windows OS Function Apps. You can refer to this tutorial for implementation. Please let me if there are any additional concerns. Thank you!

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.