0
votes

Using EF 6 and Devart Entity Design and DotConnect for SQLite. I am having issues with the embedded database location when running in debug, release and after installed.

It works just fine to copy the database file to bin/Debug or bin/release and access the database using:

Data Source=database.db

in my connection string. When I run while debugging I can access the database just fine. IF I install I cannot access the database with read/write - just read only.

So...I have made the app make sure that the database (and a few other resources are available in user directory\AppData\Roaming by running this on form load:

        string basePath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\ThermalVision\";

        //Later...

            if(!File.Exists(basePath + "database.db"))
        {
            string source = AppDomain.CurrentDomain.BaseDirectory + "database.db";
            File.Copy(source, basePath + "database.db");
        }

This works fine as well when running in debug mode inside Visual Studio.

My metadata connection string currently looks like this (code is generated by Entity Developer):

    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();
    }

When this app is installed and I start I get the following error:

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.Memoizer
2.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)

I am not sure how to resolve this. My path is hard coded and the database connects just fine when I test it in Entity Developer.

It also seems that the other question here is how to handle read/write embedded resources when the resources are using in debugging mode in Visual Studio and in product when the app is installed?

1

1 Answers

0
votes

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: https://forums.devart.com/viewtopic.php?t=30956#p106308. Does this make any difference?