c# - SqlConnection in .NET -- How can I best harness connection pooling? -


I have read that the .NET connection uses pooling.

For example, if I instantiate a bunch of SqlConnection objects with the same connection string, then internally, the .net will know to use the same connection.

Is that correct?

In addition, in a large web-based application, what is the best way to "power" this?

TCP connection setting between your web application and SQL Server can be an expensive operation. Connection pooling allows connections to the database to be reused for subsequent data requests. Instead of setting up a new TCP connection on each request, a new connection is set up, when a connection is not available in the pool. When the connection is closed, it is returned to the pool where it is connected to the database, as opposed to TCP completely tearing the connection.

When you are finished with them, always close your connection. No matter what anyone says about garbage collection inside Microsoft. Always close the NET Framework, or dispute your connection explicitly, when you finish it, do not trust the Common Language Runtime (CLR) and close your connection. CLR will eventually destroy the class and close the connection, but the garbage collection will actually be on the object when you do not have a guarantee.

To use connection pooling, there are some rules to stay better. First, open the connection, do the job, and then close the connection. Instead of opening the connection and passing it through various means, it is OK to open and close the connection on each request. Second, use the same connection string (and if you are using integrated authentication identical thread identities) If you do not use the same connection string, for example, the connection string based on the logged-in user If you customize, you will not get the same optimization value provided by connection pooling. And if you use integrated authentication while identifying a large group of users, your pooling will also be less effective.

When trying to track any display problem related to connection pooling. The NET CLR Data Performance Counter can be very useful.

HTML

Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -