Friday, March 22, 2013

Note: SQLite, VSTO, System.Data.SQLite and Entity Framework

I was trying to develop a Outlook 2010 Add-In and chose to use SQLite as the database. I used VS2010 and Firefox extension "SQLite Manager". I have read article from Brice Lambson http://brice-lambson.blogspot.com/2012/10/entity-framework-on-sqlite.html. During the development, I had a few issues.

Issue 1: What is "|DataDirectory|" in app.config. It will be the root directory of the add-in. If you want to choose another location, you probably can try to add the code below.
AppDomain.CurrentDomain.SetData("DataDirectory", path);

http://msdn.microsoft.com/en-us/library/cc716756.aspx

Issue 2: Create Database is not supported by the provider.
Reason: EF provider for SQLite (System.Data.SQLite) doesn't provide database creation so you must create database and all tables manually before you launch the application.
Solution:  Add "Database.SetInitializer<EkosContext>(null);" to DbContext 

Link: http://stackoverflow.com/questions/8505999/sqlite-createdatabase-not-supported-error

Issue 3: unable to open database file
This could be a simple file permission issue. In my case, I configured the database file as "Embedded Resource" and "Copy Always".

No comments: