I have a SQLite database added to my project in the solution explorer, named testdb.s3db. What I want to do is reference it in my code without having to fully qualify the path. Currently my code is SQLiteConnection connection = new SQLiteConnection("Data Source=C:\\Users\\Chris\\Documents\\Visual Studio 2008\\Projects\\ConsoleApplication3\\ConsoleApplication3\\testdb.s3db"); Can I do this somehow so it can be run on any machine in any path? I've tried just "testdb.s3db" but it won't work. It does work as intended when I fully qualify the path.

7 Years
Discussion Span
Last Post by sknake

You want it to run on any machine with any path but don't want to fully qualify it? What is the problem with choosing a path at runtime?

You have to tell the database driver where to look for the file and typically if you do not use a fully qualified path it looks in the Start Directory for the application BUT you should not write to files in C:\Progra~1\ because of folder virtualization in Vista. For forward compatibility you should fully qualify the path and use your application's data folders. In debug you might want to hard code the path.


I was implying that the database would exist in the same folder as the executable. However when I debug the code in visual studio, it installs an executable in a folder where the database doesn't exist, so the code can't find the database. Is there a better way around this?

I don't really intend this to be "installed" into the program files folder. This is just a standalone app that i'm playing around with, and fully intend on it being run from its own folder somewhere else.


Copy the database to your \bin\Debug\ directory then. That is where your application is executed from.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.