Path spec for database file (SQLite) under debug, release and final deployment location

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
flycast
Posts: 19
Joined: Mon 04 Feb 2019 19:39

Path spec for database file (SQLite) under debug, release and final deployment location

Post by flycast » Thu 28 Mar 2019 15:14

I have a SQLite database and am having issues with where to place the database file. When debugging I have just copied the file to Bin/Debug folder and used a connection string that ends up looking like this:
base(@"metadata=DataModel1.csdl|DataModel1.ssdl|DataModel1.msl;provider=Devart.Data.SQLite;provider connection string=""Data Source=database.db;FailIfMissing=False""", "Entities")
When I deploy the database file cannot be found. I have confirmed that the database file IS actually in the same folder as the exe for the app after the app is installed.

I'd like to use the current user's appdata folder on deployment. That buries the database file in a less obvious location so less messing around by users and less possibility of accidental erasure.

Is there a way that Entity Developer's connection string can look in multiple places for a database file?

Also, I do not want to overwrite the database file once it has been installed and has been written to by the app. That would lose data.

What is the best strategy for an embedded resource like this with Entity Developer?

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Path spec for database file (SQLite) under debug, release and final deployment location

Post by Shalex » Fri 29 Mar 2019 18:27

flycast wrote: Thu 28 Mar 2019 15:14When I deploy the database file cannot be found. I have confirmed that the database file IS actually in the same folder as the exe for the app after the app is installed.
1. Please specify the exact text of the error with its full stack trace.

2. Does your application work in the deployment if you initialize the Data Source connection string parameter with an absolute path to the database file?

flycast
Posts: 19
Joined: Mon 04 Feb 2019 19:39

Re: Path spec for database file (SQLite) under debug, release and final deployment location

Post by flycast » Fri 29 Mar 2019 19:28

System.Data.Entity.Core.MetadataException: The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource. at System.Data.Entity.Core.Metadata.Edm.MetadataArtifactLoader.Create(String path, ExtensionCheck extensionCheck, String validExtension, ICollection1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
at
System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(String
paths) at
System.Data.Entity.Core.Common.Utils.Memoizer2.<>c__DisplayClass2.b__0() at System.Data.Entity.Core.Common.Utils.Memoizer2.Result.GetValue()

at System.Data.Entity.Core.Common.Utils.Memoizer2.Evaluate(TArg arg) at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetArtifactLoader(DbConnectionOptions effectiveConnectionOptions) at System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions) at System.Data.Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace() at System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection() at System.Data.Entity.Core.Objects.ObjectContext..ctor(EntityConnection connection, Boolean isConnectionConstructor, ObjectQueryExecutionPlanFactory objectQueryExecutionPlanFactory, Translator translator, ColumnMapFactory columnMapFactory) at System.Data.Entity.Core.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName) at Model.Entities..ctor() at ThermalVision.Form1.SetMachineTextBoxOptions() at ThermalVision.Form1.Form1_Load(Object sender, EventArgs e) at System.Windows.Forms.Form.OnLoad(EventArgs e) at System.Windows.Forms.Form.OnCreateControl() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)
at System.Windows.Forms.Control.CreateControl() at System.Windows.Forms.Control.WmShowWindow(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.ScrollableControl.WndProc(Message& m) at System.Windows.Forms.Form.WmShowWindow(Message& m) at System.Windows.Forms.Form.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
My connection string currently looks like this:

Code: Select all

    public Entities() : 
        base(@"metadata=DataModel1.csdl|DataModel1.ssdl|DataModel1.msl;provider=Devart.Data.SQLite;provider connection string=""Data Source=C:\Users\erics\AppData\Roaming\ThermalVision\database.db;FailIfMissing=False""", "Entities")
    {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }
I HAVE confirmed that the database.db file exists at that location.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: Path spec for database file (SQLite) under debug, release and final deployment location

Post by Shalex » Thu 04 Apr 2019 16:58

flycast wrote: Thu 28 Mar 2019 15:14Is there a way that Entity Developer's connection string can look in multiple places for a database file?
There is no way to do that.
flycast wrote: Fri 29 Mar 2019 19:28
System.Data.Entity.Core.MetadataException: The specified metadata path is not valid. A valid path must be either an existing directory, an existing file with extension '.csdl', '.ssdl', or '.msl', or a URI that identifies an embedded resource.
The error is not related to the ADO.NET connection and occurs on the EF level.
1. The reason of the error could be missing '.csdl', '.ssdl', or '.msl' files. Did you copy these files with your application during deploy?
2. Confirm that the application you deploy is built on the workstation where dotConnect for SQLite Professional is installed.
3. Try building your project with both CopyToOutputDirectory and EmbedInOutputAssembly values of the Metadata Artifact Processing model property: viewtopic.php?t=30956#p106308. Does this make any difference?

If this doesn't help, please upload a small test project to some file exchange server (e.g.: www.dropbox.com) and specify the steps we should follow for reproducing the issue.

flycast
Posts: 19
Joined: Mon 04 Feb 2019 19:39

Re: Path spec for database file (SQLite) under debug, release and final deployment location

Post by flycast » Fri 05 Apr 2019 12:50

The reason of the error could be missing '.csdl', '.ssdl', or '.msl' files. Did you copy these files with your application during deploy?
That was the issue.

Post Reply