4

I just started to learn C#, and currently trying to create a simple program that read 1 row of data from SQLite database.

I've successfully created the program, but i still have to refer to the .db file with full address like :

SQLiteConnection("Data Source=C:/Users/../SQLiteStudio/dbs/mk_ii.db; Version=3;")

But this way, the .db won't be included when i create an installer. I want to make it something like when i add an image to my Solution Explorer, i can use short address like :

res/img/logo.png  --i also have copy of .db file in res/ folder

So, is there any way to include the .db file to my project? I've tried to read current directory and using |DataDirectory|, but all of those referred to the .exe file's active folder, and didn't work when i debugging since when debugging the .exe file have different directory than the project directory.

For a note, i'm using VS Community 2015 and System.Data.SQLite. Also i've tried added the .db file to Solution Explorer, but i can't seem to access through it.

1 Answer 1

4

Include your database file in your project. Set the type to Content, that will make sure the file is copied to your output directory. Use relative path in connection string.

Sign up to request clarification or add additional context in comments.

1 Comment

Ah, you're right! 4 days thinking about this and turns out only problem in properties, somehow i feel so silly. Thank you. I'm using "./res/mk_ii.db" as the relative path in connection string.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.