I tried to use ClickOnce but database is not included.
When I change database property "build action" to content then it is visible in Publish files properties.
https://msdn.microsoft.com/en-us/library/kzy0fky2.aspx
Unfortunately in such case i receive following error:
Error 2 Problem generating manifest. The process cannot access the file 'H:\Repos\InstalmentsManagement\Installments.Wpf\Database\installments.sqlite' because it is being used by another process. Installments.Wpf
My connection string is:
<connectionStrings>
<add name="installmentsEntities" connectionString="metadata=res://*/InstallmentsModel.csdl|res://*/InstallmentsModel.ssdl|res://*/InstallmentsModel.msl;provider=System.Data.SQLite.EF6;provider connection string="data source=|DataDirectory|\Database\installments.sqlite"" providerName="System.Data.EntityClient" />
</connectionStrings>
Moreover I did following on startup in order to detect datadirecory:
protected override void OnStartup(StartupEventArgs e)
{
string executable = System.Reflection.Assembly.GetExecutingAssembly().Location;
string path = (System.IO.Path.GetDirectoryName(executable));
AppDomain.CurrentDomain.SetData("DataDirectory", path);
base.OnStartup(e);
}
If you are getting “The process cannot access” a local data file, you are probably opening it yourself and not closing it.
ClickOnce defines
|DataDirectory|as the installer data folder. If your connection string is|DataDirectory|\Database\installments.sqlitethen you need to mark your project'sDatabasefolder, not theinstallments.sqlitefile, as the data file. Or you could change your connection string to|DataDirectory|\installments.sqliteSetDatadoes not “detect” DataDirectory, it replaces it. Do not callSetDataas that will replace ClickOnce's value. If you need to know the installer target data folder you can callAppDomain.CurrentDomain.GetData("DataDirectory"), but if you are using ADO.NET you do not even need to do that; ADO.NET will replace|DataDirectory|in connection strings with the path to the installer data folder.You probably just need to remove your
OnStartupmethod; that's what is wrecking things.