1

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=&quot;data source=|DataDirectory|\Database\installments.sqlite&quot;" 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);      
    }
komizo
  • 1,052
  • 14
  • 21

1 Answers1

2

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.sqlite then you need to mark your project's Database folder, not the installments.sqlite file, as the data file. Or you could change your connection string to|DataDirectory|\installments.sqlite

SetData does not “detect” DataDirectory, it replaces it. Do not call SetData as that will replace ClickOnce's value. If you need to know the installer target data folder you can call AppDomain.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 OnStartup method; that's what is wrecking things.

Dour High Arch
  • 21,513
  • 29
  • 75
  • 90
  • 1
    i am using entity framework. I removed code from OnStartup function. I removed Database folder moved installments.sqlite outside it, changed connection string but publish still does not copy that file – komizo Jun 26 '15 at 16:52
  • 1
    I suspect something, most likely your own code, is opening installments.sqlite and not closing it. Finding that thing will probably require physical access to your development machine. [Process Explorer](https://technet.microsoft.com/en-us/sysinternals/bb896653.aspx) may help you in this. – Dour High Arch Jun 26 '15 at 17:22
  • 1
    sorry, it occured that when I additionally chandged build action to content then it succed along with your advise - thanks – komizo Jun 26 '15 at 17:25