找不到 sqlite 文件,不确定 c# 在做什么

发布于 2024-11-26 10:19:15 字数 1333 浏览 9 评论 0原文

我有一个工作正常的程序,我可以从程序内访问数据库...但我的问题是这样...数据库不在我的计算机上...至少在我的位置可以找到它。我尝试搜索所有 .db 文件,但不存在。我希望能够复制此文件并添加到我正在制作的程序中,并将其备份到其他地方。但我找不到它。我使用安装程序将其正确安装到我名下的程序文件中,这也有效,程序运行并从数据库读取。这是我用来创建数据库的代码,因为如果您尝试打开连接并且文件不存在,sqlite 将创建一个数据库。 B

我再次检查

public void createDB()
    {
        string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(sqlLib)).CodeBase);
        string[] brokenPath = path.Split('\\');
        path = "";
        for (int i = 1; i < brokenPath.Length; i++)//parse file name and rebuild to remove wrong chars
        {
            path += brokenPath[i];
            if (i < brokenPath.Length - 1)
                path += "\\";
        }

        MessageBox.Show(path);

        if (!File.Exists(path += "\\fman.db"))
        {
            MessageBox.Show("File doesn't exist");
            SQLiteConnection db = dbConnect();
            popDB(db);
            dbClose(db);
        }

哪个,工作正常...

并且我使用创建数据库所以

static public SQLiteConnection dbConnect()
    {
        string ConnectString = "Data Source = fman.db;";
        SQLiteConnection db = new SQLiteConnection(ConnectString);
        db.Open();
        return db;
    }

,我可以很好地访问数据库并读/写文件,但我在任何地方都找不到该文件。如果我在调试模式下工作,它就在 bin/debug 文件中,但是当我安装它时,它会去哪里?

请提前寻求帮助

I have a program that works correctly and I can access the database from within the program... But my issue is this... The db is no where on my computer... at least where I can find it. I have tried searching for all .db files and it wasn't there. I want to be able to copy this file with an addition to my program that i am making, and back it up elsewhere. But I can't find it. I use an installer to install it correctly to program files under my name and that works too, the program runs and reads from the database. So here is the code I use to create the db since sqlite will create a db if you try to open a connection and a file doesn't exist. B

I check with

public void createDB()
    {
        string path = Path.GetDirectoryName(Assembly.GetAssembly(typeof(sqlLib)).CodeBase);
        string[] brokenPath = path.Split('\\');
        path = "";
        for (int i = 1; i < brokenPath.Length; i++)//parse file name and rebuild to remove wrong chars
        {
            path += brokenPath[i];
            if (i < brokenPath.Length - 1)
                path += "\\";
        }

        MessageBox.Show(path);

        if (!File.Exists(path += "\\fman.db"))
        {
            MessageBox.Show("File doesn't exist");
            SQLiteConnection db = dbConnect();
            popDB(db);
            dbClose(db);
        }

Which again, works fine...

Ands I create the db with

static public SQLiteConnection dbConnect()
    {
        string ConnectString = "Data Source = fman.db;";
        SQLiteConnection db = new SQLiteConnection(ConnectString);
        db.Open();
        return db;
    }

So, I am able to access the db fine and read/write to the file but I can't find the file anywhere. If I work in debug mode it is right there in the bin/debug file, but when I install it, where is it going?

Ty all kindly in advance for any help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

失而复得 2024-12-03 10:19:15

当我也遇到这种情况时,这让我摸不着头脑。

我终于在我的个人资料的 AppData\Local\VirtualStore 文件夹中找到了我的数据库文件。

This had me scratching my head for quite a while when it happened to me too.

I finally found my database file in the AppData\Local\VirtualStore folder in my profile.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文