- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个简单的 C# 代码,我在其中尝试多次打开和关闭连接。我如何才能确保我的新连接来自连接池并且它不会访问数据库?
using System;
using System.Data;
using System.Data.Odbc;
using System.Collections.Generic;
namespace LBSService
{
class MyClass {
public static OdbcConnection connection = null;
public void TestConnection()
{
string connectionstring = @"Dsn=my_database.IServer;Host=IServer;
Database=my_database;Uid=informix;
Pwd=Some@123";
for (int i = 1; i <= 50; i++)
{
string StrQuery = "select * from capture_files";
connection = new OdbcConnection(connectionstring);
connection.Open();
connection.Close();
}
}
}
}
我有必须打开 ODBC 连接的限制,因此首选与 ODBC 相关的答案。
我的“连接”对象中是否有任何数据成员或我可以实际看到池中有多少未使用的连接以及我的应用程序使用了多少的东西。
提前致谢...
最佳答案
"How can I ensure that my new connections are coming from connection pool and that it is not hitting the database"
这是一个有点错误的逻辑。连接池在客户端。即使您重用池中的连接,任何命令仍然必须访问数据库。
如果您有完全相同的连接字符串(甚至大小写),那么您将重用池中的连接(假设它已打开,即默认值)。
连接池存在的原因是因为建立连接需要一些开销。
SQL Server Connection Pooling :
Connecting to a database server typically consists of several time-consuming steps. A physical channel such as a socket or a named pipe must be established, the initial handshake with the server must occur, the connection string information must be parsed, the connection must be authenticated by the server, checks must be run for enlisting in the current transaction, and so on.
In practice, most applications use only one or a few different configurations for connections. This means that during application execution, many identical connections will be repeatedly opened and closed. To minimize the cost of opening connections, ADO.NET uses an optimization technique called connection pooling.
Connection pooling reduces the number of times that new connections must be opened. The pooler maintains ownership of the physical connection. It manages connections by keeping alive a set of active connections for each given connection configuration. Whenever a user calls Open on a connection, the pooler looks for an available connection in the pool. If a pooled connection is available, it returns it to the caller instead of opening a new connection. When the application calls Close on the connection, the pooler returns it to the pooled set of active connections instead of closing it. Once the connection is returned to the pool, it is ready to be reused on the next Open call.
Only connections with the same configuration can be pooled. ADO.NET keeps several pools at the same time, one for each configuration. Connections are separated into pools by connection string, and by Windows identity when integrated security is used. Connections are also pooled based on whether they are enlisted in a transaction.
关于C# 如何 "verify"新连接实际上正在从连接池中重用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9002939/
渐进增强和优雅降级基本是一回事吗? 最佳答案 不完全是。他们从不同的 Angular 解决类似的问题。 “优雅的降级”意味着你有漂亮的功能,并且可以在不支持它的浏览器中处理它不那么漂亮(但仍然需要它以
在过去的几周里,我一直在调优和处理 PostgreSQL,我将在我的下一个项目中使用它。 我的规范是: DigitalOcean 8 核 16GB SSD x2(一个用于数据库,另一个用于 Web)
我看过很多关于负数模的问题的答案。每一个答案都放了标准 (a/b)*b + a%b is equal to a 解释。我可以用这种方法计算任何模数,而且我知道有必要使用一个模数函数,如果它是负数,则将
关闭。这个问题是opinion-based .它目前不接受答案。 想要改进这个问题? 更新问题,以便 editing this post 可以用事实和引用来回答它. 关闭 9 年前。 Improve
The docs假设所有标签都存储在 .hgtags 中,但这里显然存在一些黑魔法。 我的标签如下所示: mbayazit:~/test$ cat .hgtags 0d80b6ba4ba3b51a44
我正在尝试强制删除待处理的更改列表。所有文件(20 个旧文件)都是新文件,但尚未提交/提交。所以在 p4Win 中,它们显示红色 + 十字。我无法从更改列表中删除这些文件。我该如何删除这些文件? 感谢
如果我要删除的文件不属于工作区,那么如何从工作区的目录中删除文件? 我的文件系统上有一个目录,其中包含从 perforce 获取的文件,但在某些进程运行后,它会在这些目录中创建一些新文件。 是否有 p
就是好奇这个。以下是同一功能的两个代码片段: void MyFunc1() { int i = 10; object obj = null; if(something) ret
我对使用约束布局还很陌生,我在调整布局大小方面遇到了问题,我希望它能够响应,这样我就不必再为不同的屏幕尺寸制作 10 个布局。在布局编辑器中,一切在不同尺寸下看起来都很完美,但实际上并非如此。 我做了
按照目前的情况,这个问题不适合我们的问答形式。我们希望答案得到事实、引用或专业知识的支持,但这个问题可能会引发辩论、争论、投票或扩展讨论。如果您觉得这个问题可以改进并可能重新打开,visit the
如果试图修改声明为 const 的对象,const 类型限定符会导致编译器发出错误消息,但这还不够保护。例如以下程序修改声明为 const 的数组的两个元素: #include int main(v
我不得不问这个,因为:我唯一知道的是,如果断言失败,应用程序就会崩溃。这就是为什么要使用 NSAssert 的原因吗?或者这样做还有什么好处?将 NSAssert 置于我在代码中所做的任何假设之上是否
我正在处理我的操作系统项目的 POSIX 子系统,并且我已经达到了我想要处理 pthreads 支持的地步。但是,我不确定我应该在多大程度上实现它们。 最常用的 pthreads 功能是什么?现在有什
这个问题不太可能对任何 future 的访客有帮助;它只与一个小的地理区域、一个特定的时间点或一个非常狭窄的情况相关,通常不适用于互联网的全局受众。如需帮助使这个问题更广泛适用,visit the h
我正在尝试运行测试类,但抛出错误实际上有零交互。 class Xtractor{ void extractValues(request,Map m1, Map m2,Map m3){
我有一个抽象类UIObject,如下所示: public abstract class UIObject { private final int tabOrder; public UI
这是我尝试在 emacs lisp 中进行一些计算时得到的... (+ 2082844800. 1274511600.0) => 1209872752.0 (+ 2082844800.0 127451
我想用一条垂直线将屏幕分成两部分。垂直线应该从屏幕底部一直延伸到导航栏。如果我们使用 html/css,我只会有 2 个 div,并在右侧 div 上放置一个左边框。如果有办法在 View 的单侧放置
我有一个EC2实例可以正常工作数月(仍在开发中,应用程序尚未启用),但是我只是意识到我什至不知道如何根据流量来扩大/缩小EC2实例。 亚马逊提供的大量服务是压倒性的,我对此感到非常困惑。 最初,虽然我
考虑这个代码: int i = 1; int x = ++i + ++i; 我们对编译器可能会为这段代码做些什么有一些猜测,假设它可以编译。 两者 ++i返回 2 ,导致 x=4 . 一 ++i返回
我是一名优秀的程序员,十分优秀!