0

I need some help, I have a SQL Server CE database in my project and I open the connection when loading the first form and keep it open, you know the usual:

if (con.State == ConnectionState.Closed)
{
    con.Open();
}

It works perfectly fine, but that first moment when it's opening the connection is toooooo long.

My question is, isn't there a way to make that opening process go a little faster so that my program's users won't fall asleep waiting for it to open?

Thanks in advance...

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
KarinaFx2
  • 11
  • 1
  • 2
    What is "toooooo long"? Can you give an example (ie. 17ns, 42 seconds, 2 hours 15 minutes, a day and a haircut)? Also, where is the database file located? On the same machine? network share? – Lasse V. Karlsen Apr 01 '15 at 20:31
  • it's on the same machine, and not an old one. – KarinaFx2 Apr 02 '15 at 11:52

2 Answers2

0

A given API may have a bunch of overloads on an open command but what's happening underneath is pretty much the same. Unless you switch to a completely different API or another db there is no way to "speed" up the process.

The only thing you can do is to mitigate the issue by moving the opening of the connection to some other part of the application's life-cycle where the user might not notice or mind a delay.

One trick that is widely used is to implement this slight-of-hand is to do your initialization while a splash screen is being displayed to the user. The splash screen might have some fancy graphics and text to "entertain" the end user. You will even see the splash screen updated with what the app is doing at that particular time. Not terribly useful but might be entertaining enough to the user to distract from the delay.

I did this once when users were complaining of an initialization step taking too long. After I published the change the end users swore that the app performed much better. It didn't really. I only manipulated perception.

Paul Sasik
  • 79,492
  • 20
  • 149
  • 189
0

There are a number of reasons, why opening a SQL Compact connection can be extra slow:

1: The database has been created on another platform (For example Windows 7 => Windows XP)

2: The ACL (Access Control List) on the RSA folder is corrupt

3: Invalid Internet Proxy configuration

I have much more details and suggestions for workaround in my blog post here: http://erikej.blogspot.dk/2013/08/faq-why-is-opening-my-sql-server.html

ErikEJ
  • 40,951
  • 5
  • 75
  • 115