« SQL Server Express--Deploying the database | Main | Getting and Staying Connected (Updated October 2007) »

Connect-Query-Disconnect in Client/Server

In response to a newsgroup question where an ASP developer (who had seen the light) wanted to know if it was still necessary to immediately close connections or if it was okay to keep them open.
________________________________
Unless your server is supporting many hundreds of users or you're under a licensing restriction, you can easily get away with creating and holding connections--lots of them. The disadvantage to this approach is that it ties up some resources on the server to maintain your connection state--but so does the connection pool approach. The advantage is that you can build and maintain state on the server. This state can consist of server-side temp tables, specific SET configurations and server-side cursors. These can't be leveraged in an ASP environment (which is probably why they were not brought forward with ADO.NET). For example, you can build a #temp table that contains user-specific rowsets, index it and use it in subsequent JOIN statements to (dramatically) improve performance. In the past (before connection pooling) we used this approach quite effecitvely and simply timed out the connections after N idle minutes.

TrackBack

TrackBack URL for this entry:
http://betav.com/blogadmin/mt-tb.cgi/137

Comments

Bill, If you really wanted to keep a connection open within asp.net from page to page, couldn't you store it in cache? I am not sure this is a good practice, but I think it can be done.

Ah, that's what the connection pool is for. However, unless you disarm it, the pooler resets the connection on each use. It can be very problematic to leave state on the connection--the practice is not recommended.

Post a comment

(If you haven't left a comment here before, you may need to be approved by the site owner before your comment will appear. Until then, it won't appear on the entry. Thanks for waiting.)