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.
4,321 questions
SQL Server
SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,808 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,306 questions
{count} votes

1 answer

Sort by: Most helpful
  1. ChaitanyaNaykodi-MSFT 23,106 Reputation points Microsoft Employee
    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