views:

60

answers:

3

For some reason it takes 7 seconds to open a connection to a sql server database for the firt time, subsequent connections takes a second. any idea what could be the reason?

I'm using C# and asp.net

Its after compilation, i essence every time i restart the site, which means every time it needs to actualy create the "first" connection. i understand that setting up connection pooling has overhead, but i have never seen that i should take 7 second to set it up.

A: 

is this after a compile each time? Is the "lagtime" due to JIT compiling rather than the SqlConnection itself?

Anthony Shaw
I updated my question to answer your question, i short it's compilation.
Shrage Smilowitz
A: 

The first time the connection has to be established which has a lot of overhead. Each subsequent connection is using connection pooling (assuming you have the same connection string) and the initial setup does not need to be done.

Edit: see this link or this one for some info on connection pooling.

TLiebe
I understand the reason, but i have not seen anywhere that it should take 7 seconds.
Shrage Smilowitz
+1  A: 

As well as connection pooling and CLR compilation, don't forget that the data and plan caches on the database server could be "cold" too...

I've seen first calls on a very "cold" web site take 5-10 seconds to respond from button click (for example, "search") to the data ending up on screen.

gbn
Might be the reason i will keep an eye and update.
Shrage Smilowitz