Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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...

like image 881
Optimus7 Avatar asked Oct 16 '12 06:10

Optimus7


2 Answers

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.

like image 103
Barton Avatar answered Nov 03 '22 04:11

Barton


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)
);
like image 41
Olivier Jacot-Descombes Avatar answered Nov 03 '22 06:11

Olivier Jacot-Descombes