Building Unity game that includes SQLite database ,How to build Unity game that includes SQLite Database.

I am working on a game using Unity 2019.3.1f1 Personal. The game I made includes a SQLite database and, inside the editor, works as intended with no issues. However, after building the game and running the executable the game does not connect to the database. I am sure it is due to the single error I still get inside the editor though I have no resolution for this issue. Attached is the error and my Plugins folder.

You have two problems here: error in Unity Editor and issue in build.

To solve the first:

  • The following files must be inside the Plugins folder: Modo.Data.dll, Mono.Data.Sqlite.dll, sqlite3.def and sqlite3.dll. You can download here.

To solve the second:

When you build your project, Unity exports the database EMPTY, that is, without tables. Then do the following:

  • Into your database manager script, add a function that create the tables you need in your database. Add the “IF NOT EXISTS” clause in every CREATE TABLE to prevent future Sql exceptions.
  • Call the new function from the Start() function after find the database.

Example DatabaseManager.cs script:

    string conn;
    string sqlQuery;
    IDbConnection dbconn;
    IDbCommand dbcmd;
    string DATABASE_NAME = "/mydatabase.s3db";

    void Start()
        string filepath = Application.dataPath + DATABASE_NAME;
        conn = "URI=file:" + filepath;
        dbconn = new SqliteConnection(conn);

    private void CreateTable()
        using (dbconn = new SqliteConnection(conn))
            dbcmd = dbconn.CreateCommand();

            sqlQuery = "CREATE TABLE IF NOT EXISTS [table_name] (" +
                "[name] VARCHAR(255)  NOT NULL," +
                "[age] INTEGER DEFAULT '18' NOT NULL)";

            dbcmd.CommandText = sqlQuery;

  • Go to Player Settings / Other Settings and be sure .Net Standard 2.0 is selected in Api Compatibility Lebel field.
  • Go to Build Settings and select x86_64 in Architecture field (Windows Platform).
  • Do a new build and check if game run correctly.
  • Let me know if this post helped you to solve your issues :smiley:

I dont know much about SQLite database or anything but i saw a link from a unity forum about this problem that helped alot of people. Hope this link works for you too.

I’m building my game and i have little knowledge about sqlite database you can use this link and study about it. Life saver