System.Data.SQLite slow connect for non-admin users

782 views Asked by At

I have a .NET 4 application (in mixed mode) with System.Data.Sqlite (1.0.82) for database access to an encrypted database.

When I install the application to "c:\program files\myfolder" the connect to the sqlite database file is slow. Log files show that it's the sqlite connect statement that is delayed by a few seconds.

The problem does not occur when I do the following:

  • Run the application with admin privileges
  • Install any other place than c:\program files\
  • Install the application to c:\program files\, but move the database to another folder.

I have no clue what can be the cause of this...

2

There are 2 answers

0
Barton On BEST ANSWER

If the DB file is in the application directory then it's most likely that the UAC is moving it to the "...appdata\Local\VirtualStore\Program Files" directory. Best practice is to create your own appdata\MyApp folder and copy the pristine DB out of the c:\program files\MyApp folder.

0
Olivier Jacot-Descombes On

It helps to open the database in read-only mode. (You should keep only read-only stuff in the program files folder anyway.)

Just append ";Read Only=True" to the connection string.

private const string CONN_TEMPL = "Data Source={0};Version=3;Read Only=True";
var conn = new SQLiteConnection(
    String.Format(CultureInfo.InvariantCulture, CONN_TEMPL, databasePath)
);