SQL connection pooling in Azure Functions

8.2k views Asked by At

In traditional webservers you would have a SQL connection pool and persistent connection to the database.

But I am thinking of creating my entire application as Azure Functions. Will the functions create a new connection the SQL server everytime its called upon?

2

There are 2 answers

4
brettsam On BEST ANSWER

Azure Functions doesn't currently have SQL as an option for an input or output binding, so you'd need to use the SqlClient classes directly to make your connections and issue your queries.

As long as you follow best practices of disposing your SQL connections (see this for example: C# SQLConnection pooling), you should get pooling by default.

Here's a full example of inserting records into SQL from a function: https://www.codeproject.com/articles/1110663/azure-functions-tutorial-sql-database

0
Vipin On

Although this is already answered, I believe this answer can provide more information.

If you are not using connection pool then probably you are creating connection every time function is invoked. Creating connection has associated cost, for warmed up instances it is recommended to use connection pool. max number of connection should also be chosen cautiously since there can be couple of parallel functions app running (as per plan).

This is example of connection pool.