为什么CodeFluent默认保持数据库连接打开? [英] Why does CodeFluent keep database connections open by default?

查看:101
本文介绍了为什么CodeFluent默认保持数据库连接打开?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

CodeFluent默认情况下使数据库连接保持打开状态。这样做的好处是什么?在使用后通过设置closeConnectionOnCompleteCommand = true关闭它们时,它们有什么缺点?

CodeFluent keeps database connections open by default. What are the advantages of doing so? Are their any disadvantages when they are closed after use by using the setting closeConnectionOnCompleteCommand="true"?

关于托马斯

推荐答案

CodeFluent运行时针对每个线程自动处理数据库连接。主要好处是不必担心管理连接,因此可以使用客户生成的类来完成此操作:

The CodeFluent Runtime handles database connection automatically, per thread. The main benefit is to not worry about managing connections, so you can do this with a "customer" generated class:

Customer customer = new Customer();
customer.Name = "Joe"
customer.Save();

,并且您从未使用过连接对象或连接字符串,因为它们已配置且处于环境状态。 10年前,当产品创建时,人们不太习惯 using 语句(对于VB.NET甚至不存在)。在引擎盖下,连接当然是打开的,并且永远不会关闭。实际上,它与ADO.NET池非常相似。

and you never used a connection object nor a connection string because they're configured and are ambient. 10 years ago when the product was created, people were not very used to the using statement (and it did not even existed for VB.NET). Under the hood, a connection is of course opened, and never closed. It's rather similar to what the ADO.NET pool does in fact.

您不需要使用 closeConnectionOnCompleteCommand 参数,如果所有运行时执行链(ADO连接池的最大大小,每个处理器的IIS最大线程数,数据库服务器的最大连接数等)均已配置一致。

You shouldn't need to use the closeConnectionOnCompleteCommand parameter if all the runtime execution chain (ADO connection pool max size, IIS max thread per processor, database server max connection, etc.) is configured consistently.

例如如果池中的最大连接数为100,而SQL Server中的最大连接数为10,则不一致,因为在某一时刻,池中可能有更多的连接可供SQL Server接受,并且您将从SQL Server中获取异常

For example if you have 100 max connection in the pool and 10 max connections in SQL server, that's not consistent, because at one moment in time, you may have more connections in the pool that the SQL Server will accept and you will get exceptions from SQL server.

从历史上看,该错误很少发生,因为版本7之前的IIS之类的服务器(或者可能是Windows或.NET改变了它的实际工作方式)没有池中真正旋转的线程(您只会获得相同数量的线程)。现在,从IIS 7开始,线程由于某种原因一直在变化,因此连接将自动更快地创建,并且默认情况下不会关闭(每个线程一个)。因此,您会更经常收到该错误。第一个解决方案是确保每个最大配置一致。第二种解决方案是添加 closeConnectionOnCompleteCommand 参数,并使每个人的生活更轻松。

Historically, that error happened only seldom, because a server like IIS prior to version 7 (or maybe it's Windows or .NET that changed how it really works) did not really "rotated" threads in the pool (you'd get only the same few threads). Now since IIS 7, threads are changing all the time for some reason, and so connections will be created automatically more rapidly and not closed by default (one per thread per default). So you would get that error more often. The first solution was to make sure every "max" is configured consistently. The second solution was to add that closeConnectionOnCompleteCommand parameter and make life easier for everyone.

这篇关于为什么CodeFluent默认保持数据库连接打开?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆