简体   繁体   English

WPF C# 安装的应用程序 SQLite 数据库位置

[英]WPF C# Installed application SQLite database location

I have just compiled and installed an application that generates and uses an SQLite database.我刚刚编译并安装了一个生成和使用 SQLite 数据库的应用程序。

In my App.config file, my connection string is like this:在我的 App.config 文件中,我的连接字符串是这样的:

<add name="DBContext" connectionString="data source=.\DB.sqlite" providerName="System.Data.SQLite" />

In my debug/release, I can see that the DB.sqlite file is created in the same folder.在我的调试/发布中,我可以看到 DB.sqlite 文件是在同一个文件夹中创建的。

However, when I have installed the compiled application, it goes to a directory called:但是,当我安装了编译后的应用程序时,它会转到一个名为:

C:\Users\uua\AppData\Local\VirtualStore\Program Files (x86)\App

Is there a way to make sure the database appears in a custom location or in the same folder as my installed application?有没有办法确保数据库出现在自定义位置或与我安装的应用程序相同的文件夹中?

Is there a way to make sure the database appears in a custom location or in the same folder as my installed application?有没有办法确保数据库出现在自定义位置或与我安装的应用程序相同的文件夹中?

You could always use an absolute path:您始终可以使用绝对路径:

<add name="DBContext" connectionString="data source=c:\folder\DB.sqlite" providerName="System.Data.SQLite" />

The obvious drawback with this is that you need to make sure that the directory actually exists on the machine(s) where your app is installed.这样做的明显缺点是您需要确保该目录实际存在于安装您的应用程序的机器上。

You may want to consider setting the connection string programmatically .您可能需要考虑以编程方式设置连接字符串

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM