I want to be able to use a relative path to use a SQLite DB on more than 1 pc. the connectionstring in the app.config looks like this now:
<add name="DBPersonEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SQLite;provider connection string='data source="C:\Users\Dreeze\Documents\Test DB2\DBPerson.s3db"'" providerName="System.Data.EntityClient" />
The DB file is in the same folder as the app... i would like to make the path relative so it refers to the apps folder. Can anyone help me change this connectionstring?
Use this connectionString
<add name="DWContext" connectionString="Data Source=|DataDirectory|DBPerson.s3db" providerName="System.Data.SQLite" />
Then set DataDirectory path on your code before initializing Context objext.
string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
string path = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", path);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With