Why Opening a Database Connection Is Very Slow?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

jaykchan_at_hotmail.com
Date: 12/13/04


Date: 13 Dec 2004 07:02:36 -0800

I would like to know why this takes a long time to open a database
connection to a SQL Server 2000 database in a server. This doesn't
happen all the time. This tends to happen when I am opening the
database connection for the first time after I have opened the project.
I find that I may take 2 minutes or so to open a database connection.
After that, I find that re-opening the database connection tends to be
faster (from 15 seconds to 1 second or less). What is happening here
and how can I speed up the database connection?

The way that I open a database connection is:

Public Shared m_cnn As System.Data.SqlClient.SqlConnection = Nothing
. . .
Dim sConnString As String
sConnString = "workstation id=Pocket_PC;" & _
"packet size=4096;" & _
"user id=ABC;password=XYZ;" & _
"data source=SQLSRVMS2;" & _
"persist security info=False;" & _
"initial catalog=MyDB"

m_cnn = New System.Data.SqlClient.SqlConnection
m_cnn.ConnectionString = sConnString
m_cnn.Open() <--- This can be very slow

BTW, I can quickly open a database connection from my desktop
application (such as a Query Analyzer). I just have this problem
opening a database connection when I am running the CF VB.NET
application in emulation mode (I don't have a real Pocket PC yet).
Please help. Thanks.

Jay Chan



Relevant Pages

  • Re: Help ! -> Distributed BL and Database Access
    ... I have one server located in a remote part of the country ... method the data within the object will be comitted to the database. ... reference to the database connection and then send it to the client (by ... value - to move the work off onto the client). ...
    (microsoft.public.dotnet.framework.remoting)
  • VS2005 editor context menu hosed after doing Windows Update today
    ... Whenever I right click on any method name, hoping to display the context menu that offers the "Go To Definition" option, instead I get a database connection dialog, which takes four clicks on the Cancel button before it goes away :-( See facsimile below. ... Use SQL Server Authentication ...
    (microsoft.public.vstudio.development)
  • Re: [PHP] uh oh, I defined a resoruce
    ... I don't agree that "Global variables are evil." ... going to use only for a database connection, IMO, is perfectly fine. ... By specific globals I mean that I have a "namespaced" entry such as ...
    (php.general)
  • Re: [PHP] uh oh, I defined a resoruce
    ... I don't agree that "Global variables are evil." ... going to use only for a database connection, IMO, is perfectly fine. ... By specific globals I mean that I have a "namespaced" entry such as ...
    (php.general)
  • Re: Database connections and try catch finally?
    ... You never know when you'll get an exception doing database IO. ... > finally statement when opening a database connection, ... > conn = new SqlConnection; ... > SqlConnection conn = new SqlConnection; ...
    (microsoft.public.dotnet.framework.adonet)