Summary
When doing the C/s project, if you use Ef+sqlite, we do not know where the client will be installed, and need to dynamically set the path of the db.
Solutions
/// <summary> /// Data Context /// </summary> Public class Mycontext:dbcontext { public mycontext () base(new sqliteconnection ( @ "Data source=c:\users\wolfy\appdata\local\client\data\my.db; "),false) { } }
It is necessary to mention another way of setting
< connectionStrings > < name= "ConnStr" connectionString= "Data source=| Datadirectory|\my.db " providerName=" System.Data.SQLite.EF6 "/> </ connectionStrings >
DataDirectory can be set in the program
AppDomain.CurrentDomain.SetData ("DataDirectory", AppDomain.CurrentDomain.BaseDirectory);
Found this way, set in the EXE directory under the function, but change the directory seems to be invalid. Guess, the way SQLite looks for database files, it should be found by default from the directory where the EXE.
Reference
Http://www.cnblogs.com/liuguangyin/p/6572734.html
Ef+sqlite setting the connection string dynamically