sqlite.net-corevisual-studio-2019localapplication-data

Where in my Visual Studio project should I copy a SQLite database, and do I need to copy it from there?


I migrated a SQL Server Express database to SQLite (using a utility I downloaded from here).

Now I want to add this SQLite database to a C# project in Visual Studio.

I cannot find information on where that should be stored, exactly. There is what seems to be a pretty good article here, about the process, but it's kind of vague as to just where to put the db. It says, "The first step is to copy your database in to the Visual Studio project and, from the Properties window, set the Build action to Content."

So is there a specific place where the database file should, or must, be placed?

Also, can I leave the database there while querying it from within the application code, or does it need to be copied to the user's ApplicationData.Current.LocalFolder?

That is what seems to be at least strong implied by that article, which shows code for doing so.


Solution

  • So is there a specific place where the database file should, or must, be placed?

    You can keep it in root directory of your project. If you like to follow specific folder structure, you can do that as well but there isn't any restriction as to where you must store your sqllite db file.

    Also, can I leave the database there while querying it from within the application code, or does it need to be copied to the user's ApplicationData.Current.LocalFolder? That is what seems to be at least strong implied by that article, which shows code for doing so.

    When you set a file property to Content in Build action, that file will be copied to your output directory, Release or Debug directory depending on what is your current build configuration and ApplicationData.Current.LocalFolder refers to the folder from which your application is running so it will work just by setting Build action to Content.