7

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?

1
  • 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. Commented Apr 11, 2019 at 15:51

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

4 Comments

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.
I agree with Semprini.
@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".
I don't think there is by default connection pool available.
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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.