views:

1022

answers:

4
  • What is it?
  • How do I implement connection pooling with MS SQL?
  • What are the performance ramifications when
    • Executing many queries one-after-the other (i.e. using a loop with 30K+ iterations calling a stored procedure)?
    • Executing a few queries that take a long time (10+ min)?
  • Are there any best practices?
+3  A: 

Connection pooling is a mechanism to re-use connections, as establishing a new connection is slow.

If you use an MSSQL connection string and System.Data.SqlClient then you're already using it - in .Net this stuff is under the hood most of the time.

A loop of 30k iterations might be better as a server side cursor (look up T-SQL cursor statements), depending on what you're doing with each step outside of the sproc.

Long queries are fine - but be careful calling them from web pages as Asp.Net isn't really optimised for long waits and some connections will cut out.

Keith
+2  A: 

A little more info on the connection pooling thing... you're using it already with SqlClient, but only if your connection string is identical for each new connection you open. My understanding is that the framework will pool connections automatically when it can, but if the connection string varies even slightly from one connection to the next, then the new connection won't come from the pool - it gets created anew (so it's more expensive).

You can use the Performance Monitor app with XP/Vista to watch SQL connections and you'll see pretty quickly whether or not pooling is being used. Look under the ".NET CLR Data" category" in Performance Monitor.

Jeff Donnici
A: 

I second Keith; if you're calling a stored procedure 30,000 times, you have far bigger problems than connection pooling.

Stu
A: 

Your question was also partially answered by this thread. A search would have revealed this.. The definition of Connection Pooling, of which a Google would have answered with the first hit being this..

Which would leave just the best practices, which I think would have been a good question :)

+1 to Keith's Answer. He has hit the nail right on the head.

Just a polite reminder from the FAQ:

You've searched the internet before asking your question, and you come to us armed with research and information about your question ... right?

Rob Cooper