0

Using a SQLite embedded database. I am using Entity Framework 6. I have the database in the bin folder when I am testing. While testing EF connects fine with the following connection string:

    public Entities() : 
            base(@"metadata=DataModel1.csdl|DataModel1.ssdl|DataModel1.msl;provider=Devart.Data.SQLite;provider connection string=""Data Source=database.db;FailIfMissing=False""", "Entities")
    {
        this.ContextOptions.LazyLoadingEnabled = true;
        OnContextCreated();
    }

When I deploy the app using ClickOnce the app does not connect to the database. I have checked to see that the database file is in the same folder with the exe file and all the dll's. It is. The path is:

C:\Users\erics\AppData\Local\Apps\2.0\3C5PX0RL.NTX\CEV4Q75L.OMO\ther..tion_680a5823070fb75b_0001.0000_db2ce9b27afbcd77

Do I need to control the location of the database.db file? If so, how do I do that with ClickOnce?

Do I need something different for the path to the database file in the connection string?

Exact 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, ICollection`1 uriRegistry, MetadataArtifactAssemblyResolver resolver)
   at System.Data.Entity.Core.Metadata.Edm.MetadataCache.SplitPaths(String paths)
   at System.Data.Entity.Core.Common.Utils.Memoizer`2.<>c__DisplayClass2.<Evaluate>b__0()
   at System.Data.Entity.Core.Common.Utils.Memoizer`2.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)
Eric Snyder
  • 1,816
  • 3
  • 22
  • 46
  • Offhand, I think this might be an issue not specifying the path where the current working directory is not where the database file is located. To verify: open a command prompt, change to the directory where the file is, and run the EXE. If it works, the cause is the current working directory not matching the directory where the files are located. If you verify this is the case, we can look at solutions. – UnhandledExcepSean Mar 27 '19 at 16:52
  • What is the full error message you get when you try to run your application and access the SQLite database? – Progman Mar 27 '19 at 19:00
  • @UnhandledExcepSean - I ran the exe file from command prompt from the correct folder. I received the same error. – Eric Snyder Mar 27 '19 at 20:35
  • @Progman - Added the error message to the original text. – Eric Snyder Mar 27 '19 at 20:36

0 Answers0