question

SaranyaSanthakumaran-0408 avatar image
0 Votes"
SaranyaSanthakumaran-0408 asked ChaitanyaNaykodiMSFT-9638 commented

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

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.



sql-server-generaldotnet-csharpazure-functions
· 3
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Hello @SaranyaSanthakumaran-0408, Thank you for reaching out. Could you please confirm if you have followed this tutorial to connect to SQL database from an azure function? And if the database used is Azure SQL Managed Instance have you enabled public endpoint?


0 Votes 0 ·

Hi @ChaitanyaNaykodiMSFT-9638 : SQL Server is not in Azure Portal . Copied the connection string from SQL db and created a new connection in Application Setting (tried in connection string as well , but no luck).

How to configure public endpoint on SQL server??? the article shows from azure , whereas mine is offline.

Thanks for the response.

0 Votes 0 ·

I tried tcpping from function app kudu console. Not sure that is the correct . But I received "AN attempt was made to access a socket in a way forbidden by its access permissions "

0 Votes 0 ·

1 Answer

ChaitanyaNaykodiMSFT-9638 avatar image
0 Votes"
ChaitanyaNaykodiMSFT-9638 answered

Hello @SaranyaSanthakumaran-0408, 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!


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.