By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,354 Members | 907 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,354 IT Pros & Developers. It's quick & easy.

Slow first connection to SQL Server

P: n/a
I have just started on a new web project. When I make the first connection
to sql server it takes about 10 to 30 seconds (varies each time) to make the
connection to the server. I am using the following code:

Dim cConnStr as String = "myconnectionstring"
Dim oCon as new SqlConnection(cConnStr)
oCon.Open() <-- Slow part

The Open line takes quite a long time.

I can use the exact same code in a windows app with exact same connect
string and it runs immediately on the same machine.

Any ideas what is going on?

I am running XP Pro SP2 and I tried disabling the firewall but it didn't
change anything. I didin't have this problem before I upgraded to Sp2.

Thanks.

Nov 18 '05 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Is this the first connection after the application has been running, or the
first time the page is hit after a recompile? If the later, it is common to
see a JIT hit. You can avoid it a bit with ngen-ing your assemblies (besides
web app), but you will still see a small hit.

Version 2.0 of the Framework makes this much nicer with precompilation
methods. NOTE: consider a project walker to hit all pages (compile) for your
web apps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
"Tommy Martin" <tm*****@xspam-tlmartin.com> wrote in message
news:Oq*************@TK2MSFTNGP11.phx.gbl...
I have just started on a new web project. When I make the first connection
to sql server it takes about 10 to 30 seconds (varies each time) to make
the
connection to the server. I am using the following code:

Dim cConnStr as String = "myconnectionstring"
Dim oCon as new SqlConnection(cConnStr)
oCon.Open() <-- Slow part

The Open line takes quite a long time.

I can use the exact same code in a windows app with exact same connect
string and it runs immediately on the same machine.

Any ideas what is going on?

I am running XP Pro SP2 and I tried disabling the firewall but it didn't
change anything. I didin't have this problem before I upgraded to Sp2.

Thanks.

Nov 18 '05 #2

P: n/a
It is the connection itself that is the problem. The page loads very fast.
Its when i click my button and hit the db to get some data that the problem
arises.

The db server is not the same as my development box. I do see that when I
run the code on the same box as the db it is very fast.

I have tried the machine name as well as the ip address in my connect string
and get the same results.

Thanks.

"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:O%****************@TK2MSFTNGP12.phx.gbl...
Is this the first connection after the application has been running, or
the first time the page is hit after a recompile? If the later, it is
common to see a JIT hit. You can avoid it a bit with ngen-ing your
assemblies (besides web app), but you will still see a small hit.

Version 2.0 of the Framework makes this much nicer with precompilation
methods. NOTE: consider a project walker to hit all pages (compile) for
your web apps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
"Tommy Martin" <tm*****@xspam-tlmartin.com> wrote in message
news:Oq*************@TK2MSFTNGP11.phx.gbl...
I have just started on a new web project. When I make the first connection
to sql server it takes about 10 to 30 seconds (varies each time) to make
the
connection to the server. I am using the following code:

Dim cConnStr as String = "myconnectionstring"
Dim oCon as new SqlConnection(cConnStr)
oCon.Open() <-- Slow part

The Open line takes quite a long time.

I can use the exact same code in a windows app with exact same connect
string and it runs immediately on the same machine.

Any ideas what is going on?

I am running XP Pro SP2 and I tried disabling the firewall but it didn't
change anything. I didin't have this problem before I upgraded to Sp2.

Thanks.


Nov 18 '05 #3

P: n/a
Also, here is my connection string if it helps.
"Server=myserver;Database=mydatabase;uid=myid;pwd= mypass;"
"Cowboy (Gregory A. Beamer)" <No************@comcast.netNoSpamM> wrote in
message news:O%****************@TK2MSFTNGP12.phx.gbl...
Is this the first connection after the application has been running, or
the first time the page is hit after a recompile? If the later, it is
common to see a JIT hit. You can avoid it a bit with ngen-ing your
assemblies (besides web app), but you will still see a small hit.

Version 2.0 of the Framework makes this much nicer with precompilation
methods. NOTE: consider a project walker to hit all pages (compile) for
your web apps.

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

*************************************************
Think outside the box!
*************************************************
"Tommy Martin" <tm*****@xspam-tlmartin.com> wrote in message
news:Oq*************@TK2MSFTNGP11.phx.gbl...
I have just started on a new web project. When I make the first connection
to sql server it takes about 10 to 30 seconds (varies each time) to make
the
connection to the server. I am using the following code:

Dim cConnStr as String = "myconnectionstring"
Dim oCon as new SqlConnection(cConnStr)
oCon.Open() <-- Slow part

The Open line takes quite a long time.

I can use the exact same code in a windows app with exact same connect
string and it runs immediately on the same machine.

Any ideas what is going on?

I am running XP Pro SP2 and I tried disabling the firewall but it didn't
change anything. I didin't have this problem before I upgraded to Sp2.

Thanks.


Nov 18 '05 #4

P: n/a
"Tommy" <tm*****@xspam-tlmartin.com> wrote in
news:uT**************@TK2MSFTNGP12.phx.gbl:
It is the connection itself that is the problem. The page loads very
fast. Its when i click my button and hit the db to get some data that
the problem arises.


I'm having the same problem as well... I know .NET uses connection pooling,
so maybe the connection pools need to be reinitialized if the connections
have been idle too long?

I haven't figured out why it takes so long relatively speaking to
reconnect.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/
Nov 18 '05 #5

P: n/a
I thought about that. I created a windows forms app and used the same
technique to connect and it does not show that problem. The connection is
instantanious as it should be.

Only ASP.NET apps are having this problem.

Tommy

"Lucas Tam" <RE********@rogers.com> wrote in message
news:Xn**************************@140.99.99.130...
"Tommy" <tm*****@xspam-tlmartin.com> wrote in
news:uT**************@TK2MSFTNGP12.phx.gbl:
It is the connection itself that is the problem. The page loads very
fast. Its when i click my button and hit the db to get some data that
the problem arises.


I'm having the same problem as well... I know .NET uses connection
pooling,
so maybe the connection pools need to be reinitialized if the connections
have been idle too long?

I haven't figured out why it takes so long relatively speaking to
reconnect.

--
Lucas Tam (RE********@rogers.com)
Please delete "REMOVE" from the e-mail address when replying.
http://members.ebay.com/aboutme/coolspot18/

Nov 18 '05 #6

P: n/a
"Tommy Martin" <tm*****@DONTSPAMMEtlmartin.com> wrote in message
news:u%****************@TK2MSFTNGP15.phx.gbl...
I thought about that. I created a windows forms app and used the same
technique to connect and it does not show that problem. The connection is
instantanious as it should be.

Only ASP.NET apps are having this problem.


Hmm - I wonder if it's credentials. When you're using your WinForms app,
you're actually logged on to the machine as yourself but ASP.NET of course
is using its own network login (I don't mean the credentials in the SQL
Connection string).

As a test, can you modify the Web.config temporarily to impersonate yourself
and see if that makes any difference?
Nov 18 '05 #7

P: n/a
Right after <system.web> i added:

<identity impersonate="true"/>

It made no difference.

Tommy
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:us**************@TK2MSFTNGP09.phx.gbl...
"Tommy Martin" <tm*****@DONTSPAMMEtlmartin.com> wrote in message
news:u%****************@TK2MSFTNGP15.phx.gbl...
I thought about that. I created a windows forms app and used the same
technique to connect and it does not show that problem. The connection is
instantanious as it should be.

Only ASP.NET apps are having this problem.


Hmm - I wonder if it's credentials. When you're using your WinForms app,
you're actually logged on to the machine as yourself but ASP.NET of course
is using its own network login (I don't mean the credentials in the SQL
Connection string).

As a test, can you modify the Web.config temporarily to impersonate
yourself and see if that makes any difference?

Nov 18 '05 #8

P: n/a
"Tommy Martin" <tm*****@DONTSPAMMEtlmartin.com> wrote in message
news:uG**************@TK2MSFTNGP15.phx.gbl...
Right after <system.web> i added:

<identity impersonate="true"/>

It made no difference.


Yes, but which user did you tell it to impersonate...?
Nov 18 '05 #9

P: n/a
Ok.. i told it to use my name and pass and the connection is pretty fast
again. First one is 1 to 2 secs. I can live with that.

This did not used to happen. I wonder if there is some config setting on my
server that needs to be changed or something else in my web.config. I am
using forms authentication in my app.

Thanks for the help.
"Mark Rae" <ma**@mark-N-O-S-P-A-M-rae.co.uk> wrote in message
news:e1**************@TK2MSFTNGP14.phx.gbl...
"Tommy Martin" <tm*****@DONTSPAMMEtlmartin.com> wrote in message
news:uG**************@TK2MSFTNGP15.phx.gbl...
Right after <system.web> i added:

<identity impersonate="true"/>

It made no difference.


Yes, but which user did you tell it to impersonate...?

Nov 18 '05 #10

This discussion thread is closed

Replies have been disabled for this discussion.