使用SQLite嵌入式数据库。我正在使用Entity Framework6。进行测试时,我的bin文件夹中有数据库。在测试EF时,使用以下连接字符串可以正常连接:
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(); }
当我使用ClickOnce部署应用程序时,该应用程序未连接到数据库。我检查了一下数据库文件是否与exe文件和所有dll位于同一文件夹中。它是。路径是:
C:\ Users \ erics \ AppData \ Local \ Apps \ 2.0 \ 3C5PX0RL.NTX \ CEV4Q75L.OMO \ ther..tion_680a5823070fb75b_0001.0000_db2ce9b27afbcd77
是否需要控制database.db文件的位置?如果是这样,我该如何使用ClickOnce?
连接字符串中的数据库文件路径是否需要其他内容?
确切错误:
> 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)