本文介绍了Azure Functions 中的 SQL 连接池的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在传统的网络服务器中,您将拥有一个 SQL 连接池和与数据库的持久连接.

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

但我正在考虑将我的整个应用程序创建为 Azure Functions.这些函数是否会在每次调用 SQL 服务器时创建一个新连接?

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?

推荐答案

Azure Functions 目前没有 SQL 作为输入或输出绑定的选项,因此您需要使用 SqlClient 类直接建立您的联系并发出您的查询.

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.

只要您遵循处置 SQL 连接的最佳实践(请参阅此示例:C# SQLConnection pooling),你应该默认获得池化.

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.

以下是从函数将记录插入 SQL 的完整示例:https://www.codeproject.com/articles/1110663/azure-functions-tutorial-sql-database

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

这篇关于Azure Functions 中的 SQL 连接池的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-07 01:20