Solved

Initial Connection to SQL Express database is...slow.

Posted on 2007-12-06
1
735 Views
Last Modified: 2013-12-16
Just set up a SQL Express database using "Microsoft SQL Server Management Studio Express" on a dedicated machine on our network.

In my program, I am basically using a SqlConnection to connect to this database via...



SqlConnectionStringBuilder sqlconnbuild = new SqlConnectionStringBuilder();

            sqlconnbuild.DataSource = "xxx.xxx.xxx.xxx\\xxxxxxxx";  //E.G. 192.168.25.24\\DBServer
            sqlconnbuild.InitialCatalog = "DatabaseNameHere";              //For example
            sqlconnbuild.ConnectTimeout = 120;                                    //I needed to set this to prevent T/O

SqlConnection conn = new SqlConnection(sqlconnbuild.ToString());
SqlDataReader reader;

SqlCommand comm = new SqlCommand("Insert SQL SELECT statement here", conn);

try
{
     conn.Open();
     reader = comm.ExecuteReader();
     //Insert general code here
}
catch (SqlException e1)
{
     MessageBox.Show(e1.Message);
}
finally
{
conn.Close();
}


But here is what happens.

I run the program (F5), I type in my login details, and then wait approximately 25 seconds and then it finally finishes and allows me access into the program.

However

If I run the program (F5), and I type the wrong login details for example, wait again for approximately 25 seconds, and obvisouly I get a message saying that I typed my login incorrectly, but if immediately after I type my correct details, the connection opens and finishes like lightning probably about 0.1 of a second or lower.

Unfortionetly every the program restarts I get the same problem on the initial login, which obviously people are only ever going to log in once so its a big problem.

Any insight would be great, thanks!

(Also the database in SQLExpress has auto-close to false, I checked that one ;o))
0
Comment
Question by:recruitit
1 Comment
 
LVL 35

Accepted Solution

by:
David Todd earned 250 total points
ID: 20439249
Hi,

SQL Express set autoclose true for user databases.

Change this to false.

Cheers
  David

PS Running the script against model will make sure that all future databases don't auto_close. Otherwise change model to the name of your database.
alter database model

set auto_close off

Open in new window

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now