SQLite doesn't work in standalone built project

Hi all!
I’m developing a little platform game with Unity and C# but I’m quite new to these tools.
In order to have a ranking in my game, I implemented a SQL database with SQLite. Here some code to access the database:

public DbConnessione()
    {
        if (!File.Exists(Application.dataPath + "/" + DatabaseName))
        {
            SqliteConnection.CreateFile(Application.dataPath + "/" + DatabaseName);
            ApriDb();
            CreaTabella();
            ChiudiDb();
        }
    }

    public void ApriDb()
    {
        try
        {
            connection = "URI=file:" + Application.dataPath + "/" + Database;
            dbconnection = new SqliteConnection(connection);
            dbconnection.Open();
        }

When I execute my code in Unity it works perfectly but when I build it and use it in the stand-alone .exe, it doesn’t work anymore. The game just freezes when it tries to open the database. I had a closer look at the exception retrieved and it addresses me to the sqlite3.dll.
I followed the instructions in the previous threads on the forum. which suggest to copy in the Assets/Plugins folder some dlls from the Unity program folder, but the game still doesn’t work.
I’ve already copied:

  • All the I18N.dlls
  • I updated sqlite3.dll to the 64 bit version.
  • Mono.Security.dll
  • System.data.dll
  • Mono.data.sqlclient.dll
  • Maybe something else too

This problem looks tricky and I’m really struggling on it. I hope someone may help me!
Thank you in advance.

My initial thought is the line

File.Exists(Application.dataPath + "/" + DatabaseName)
//or
connection = "URI=file:" + Application.dataPath + "/" + Database;

.

In the editor, Application.dataPath will point to somewhere in the Assets folder.
In a standalone windows build, Application.dataPath will point to somewhere in the designated Data folder.
For mac Application.dataPath will point into the contents folder.

Thank you so much Freaking-Pingo.

Maybe it looks stupid but I’ve realized right now that I was building my project for a x86 architecture, changing that to x86-64 finally solved the problem.

I guess the thread can be closed now…

1 Like