3
votes

I am trying to connect my new Azure Function to an on-premises SQL Server database. The Microsoft docs mention that this is possible, but I have not been able to figure it out nor have I seen any tutorials about specifically setting up a on-premises db with Azure Functions.

I want to do something similar to this tutorial.

public static async void Run(TimerInfo myTimer, TraceWriter log)
{
    var str = ConfigurationManager.ConnectionStrings["on-prem-connection"].ConnectionString;

    //open connections and call db here - I know this
}

Can I do it in a similar way to the video above where I set up a connection string and then reference that connections string in the Azure Function. If so how is that done.

Thanks you.

6
Are you asking how to do the code part in Azure Functions or how to connect to on-premises?Martyn C

6 Answers

7
votes

You would need to use something like Hybrid Connection. Check out the following link. I hope it helps: https://azure.microsoft.com/en-us/documentation/articles/web-sites-hybrid-connection-connect-on-premises-sql-server/

0
votes

Possible but using Azure function as deployed under App Service Plan.

Go to "Platform Features" and select "Networking" - there you will get the option to setup the Hybrid connection for the Azure Function.

0
votes

If you are using Linux app service plan, this is impossible. Hybrid connectins just supported by Windows type app services. You can use Vnets on Linux app service plans.

0
votes

You can connect to your onpremise sql serve via virtual machine linux or windows. You can connect your virtual machine to vpn gateway enabled vnet.

0
votes

Using VNET Integration, FunctionApp can connect to on-premise SQL / services. To begin with go with the IP of the on-premise servers (not by DNS).

It's AppsServicePlan requires to be on Standard, Premium V2's.

The subnet on the VNET must be configured appropriately to allow the RFC1918 traffic. The setup will consist of using an site2site vpn gateway if not on ExpressRoute.

-4
votes

Check this Microsoft tutorial. In regards to on premises database, you just need to replace the connection string with appropriate permission.

Use Azure functions to connect to Sql database