1

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

Bear
  • 486
  • 2
  • 8
  • 16
  • where are you installing it to? – Alastair Pitts Jul 27 '11 at 06:57
  • It gets installed into program files so program files/Alternate/FileMan is where it lives, but the db file is not in that directory – Bear Jul 27 '11 at 06:59
  • Ok, this is an extremely localised question. If you can't determine where the database is being read from, then I suggest you look at where you create it. – Alastair Pitts Jul 27 '11 at 07:02
  • I create it in the directory that the application is being run from, yet it doesn't appear there. So I can't figure out how to find it, which is my problem. I can't copy it since the file isn't in the program file folder. – Bear Jul 27 '11 at 07:03
  • http://stackoverflow.com/questions/6757457/re-embedding-sqlite-database-file-into-the-same-executable are you trying this same..? – Arunkumar Chandrasekaran Jul 27 '11 at 13:23
  • No. I use the fact that sqlite creates a db file if none exists when you try to open it. I thought it did so in the same folder as the application, and it should work. The problem I am having is the db file is not being created in the folder, but is instead somewhere else. However I cannot find it. If i delete the whole application and reinstall it, it still reads from the old database... I am not sure how that is happening. I am trying to find out where the db is being created. – Bear Jul 27 '11 at 19:06

1 Answers1

2

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.

Mihai Iorga
  • 39,330
  • 16
  • 106
  • 107
parnellij
  • 21
  • 2
  • 1
    Yeah, I probably should have updated this. As to the reason I'm still not 100% sure but from what I understand, Windows now makes silent use of folders in AppData instead of writing to the projects Program directory. I don't know why it is silent but it is just the way windows handles it. It would be interesting if it was explained as to why this is done, and how writing to the program's file is redirected. – Bear Sep 03 '12 at 00:48