在 c#.net 中,当您打开与数据库的连接时,在我的例子中是 oracle,是否涉及很多开销?我猜不是因为连接池。所以我说的正确吗,每次我打开一个连接时,它实际上从池中抓取一个打开的连接,如果池中没有可用连接,它就会打开一个新连接?
谢谢!
最佳答案
你是对的。有很多解释 ADO 连接池的好文章。例如,MSDN - SQL Server Connection Pooling (ADO.NET) ,它说:
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.
关于c# - 打开数据连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2524790/