6

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?

NoWhereToBeSeen
  • 1,404
  • 1
  • 13
  • 22
  • Just as an addendum, there is no support for python either for sql connection pooling. I tried Azure functions using python in preview, and used sql-alchemy. I contacted azure support, and there is no way to have persistent database connections. – Games Brainiac Apr 11 '19 at 15:51

2 Answers2

2

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

Community
  • 1
  • 1
brettsam
  • 2,702
  • 1
  • 15
  • 24
  • 11
    but since serverless functions are instantiated for each trigger event, isn't the connection pooling function of the SqlClient library effectively redundant? Even if the function is kept warm, it's used for a single trigger at a time and if parallelized then each instance would have a redundant connection pool. – Semprini Apr 16 '19 at 21:35
  • I agree with Semprini. – SunilS Jan 15 '20 at 07:54
  • @Semprini creating connection has some cost associated, that is reason recommendation is to have a connection pool. You can decide number of connection, depending upon number of functions available in function app etc., in that way connection creation has no cost for "warmed up instanced". – Vipin May 06 '21 at 12:40
  • I don't think there is by default connection pool available. – Vipin May 06 '21 at 13:00
0

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.

Vipin
  • 4,851
  • 3
  • 35
  • 65