安装app后,指定的元数据路径无效

问题描述 投票:0回答:1

使用EF 6和Devart实体设计和DotConnect for SQLite。我在调试,发布和安装后运行时遇到嵌入式数据库位置问题。

它可以很好地将数据库文件复制到bin / Debug或bin / release并使用以下命令访问数据库:

Data Source=database.db

在我的连接字符串中。当我在调试时运行时,我可以很好地访问数据库。如果我安装我无法通过读/写访问数据库 - 只读。

所以...我已经让应用程序通过在表单加载上运行它来确保数据库(以及用户目录\ AppData \ Roaming中的一些其他资源可用:

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

在Visual Studio内部以调试模式运行时,这也可以正常工作。

我的元数据连接字符串当前看起来像这样(代码由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();
    }

安装此应用程序后,我开始收到以下错误:

System.Data.Entity.Core.MetadataException:指定的元数据路径无效。有效路径必须是现有目录,扩展名为“.csdl”,“。ssdl”或“.msl”的现有文件,或标识嵌入资源的URI。在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()在System.Data.Entity.Core.Common.Utils.Memoizer2.Result.GetValue()
at System.Data.Entity.Core.Common.Utils.Memoizer
2上。在System.Data的System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetMetadataWorkspace(DbConnectionOptions effectiveConnectionOptions)的System.Data.Entity.Core.Metadata.Edm.MetadataCache.GetArtifactLoader(DbConnectionOptions effectiveConnectionOptions)中评估(TArg arg)。在System.Data.Entity.Core.Objects.ObjectContext..ctor的System.Data.Entity.Core.Objects.ObjectContext.RetrieveMetadataWorkspaceFromConnection()中的Entity.Core.EntityClient.EntityConnection.GetMetadataWorkspace()(EntityConnection连接,Boolean isConnectionConstructor,ObjectQueryExecutionPlanFactory) systemQueryExecutionPlanFactory,Translator translator,ColumnMapFactory columnMapFactory)at System.Data.Entity.Core.Objects.ObjectContext..ctor(String connectionString,Str位于System.Windows.Form.OnLoad(EventArgs e)的ThermalVision.Form1.Form1_Load(Object sender,EventArgs e)的ThermalVision.Form1.SetMachineTextBoxOptions()处的Model.Entities..ctor()处的defaultContainerName)。 System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible)中的Windows.Forms.Form.OnCreateControl() 在System.Windows.Forms.Forms.Conm.WandSroc上的System.Windows.Forms.WmShowWindow(Message&m)上的System.Windows.Forms.Control.CreateControl()处于System.Windows.Fornd .ScrollableControl.WndProc的System.Windows.Forms.Control.WndProc(Message&m) (Message&m)System.Windows.Form.WmShowWindow(Message&m)位于系统的System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message&m)的System.Windows.Forms.Form.WndProc(Message&m) System.Windows.Forms.NativeWindow.Callback中的.Windows.Forms.Control.ControlNativeWindow.WndProc(Message&m)(IntPtr hWnd,Int32 msg,IntPtr wparam,IntPtr lparam)

我不知道如何解决这个问题。我的路径是硬编码的,当我在Entity Developer中测试时,数据库连接正常。

似乎另一个问题是当资源在Visual Studio中以调试模式使用时以及在安装应用程序时的产品中如何处理读/写嵌入式资源?

c# entity-framework-6 devart
1个回答
0
投票

该错误与ADO.NET连接无关,并且发生在EF级别。

  1. 错误的原因可能是缺少“.csdl”,“。ssdl”或“.msl”文件。您是否在部署期间使用您的应用程序复制这些文件
  2. 确认您部署的应用程序是在安装了dotConnect for SQLite Professional的工作站上构建的。
  3. 尝试使用元数据工件处理模型属性的CopyToOutputDirectory和EmbedInOutputAssembly值构建项目:https://forums.devart.com/viewtopic.php?t=30956#p106308。这有什么不同吗?
© www.soinside.com 2019 - 2024. All rights reserved.