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.

Recommended Answers

All 3 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.