You use System.Data.Sqlite in your VS 2008/2010/2012 project and create your ADO.Net Entity Framework via Data Sources Designer and let the wizard create your DB entities and the connection string entry in App.config. The SQLite database is protected by a password.
While designing in Visual Studio, you only have to enter the password once, when creating the connection in Server Explorer. SQL Data Preview etc. works.
When you now try to load data via EF with your software, e.g. by creating a new instance and accessing a table, you suddenly get the error message „file is encrypted or not a database“.
Even if the wizard told you it put the DB password into the App.config connection string, it didn’t, you can easily check this.
You can now append your password to this connection string in App.config, but be careful: The EF connection string syntax is a bit different from strings you might know from Settings.settings, i.e. from DataSets – it is like a connection string within a connection string.
If you simply append your password to the existing string, you might get confusing error messages like „keyword not supported: ‚version'“ or „keyword not supported: ‚password'“.
App.config must not contain single quotes (‚), so it becomes even trickier to read.
Your original connection string:
<addname=„dbEntities„connectionString=„metadata=res://*/db.csdl|res://*/db.ssdl|res://*/db.msl;provider=System.Data.SQLite;provider connection string="data source=X:projectsmeowdb.sqlite;"„providerName=„System.Data.EntityClient„ />
Modified string with password:
<addname=„dbEntities„connectionString=„metadata=res://*/db.csdl|res://*/db.ssdl|res://*/db.msl;provider=System.Data.SQLite;provider connection string="data source=X:projectsmeowdb.sqlite;password=this is my password;"„providerName=„System.Data.EntityClient„ />
If your password contains spaces or other special characters, do not add additional quotes.
If you want to move the string from App.config into your source code or customize your connection string within your project, do not just copy it 1:1 to your code. You have to e.g. replace the „"“ marks with single quotes, but better use a ConnectionStringBuilder for this. Get more infos on this blog.