- Home /
Cannot access Sqlite database in final build of the game
When playing my game from the editor, I have no issues with accessing the database, however when I build the game and run it, I cannot access the database. My database is inside the path Assets/Plugins. I should have all the required DLLs in that folder as well. I have checked the output_log.txt file for my game and got the following messages:
SqliteException: Unable to open the database file
at Mono.Data.Sqlite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool) [0x00000] in <filename unknown>:0
at Mono.Data.Sqlite.SqliteConnection.Open () [0x00000] in <filename unknown>:0
This has led me to believe that my database files are in the wrong directory, or I am accessing them incorrectly. Here is the code for how I access the database:
var RoomDB = new SqliteConnection("Data Source=Assets\\Plugins\\Rooms Table.db;Version=3;");
RoomDB.Open();
If the issue is with the path of the database, where should I move them to inside the final build folder?
Any solution for this problem? I have tried all the answers but nothing worked for me.
you need add manually the DB into the final build directory, and after that find the DB
I have added manually DB within the Strea$$anonymous$$gAssets folder as like the below answers. But I can't able to write URI to access that DB within the code.
Answer by hameed-ullah-jan · Apr 11, 2019 at 07:00 AM
put your .db file in "StreamingAssets" folder, and access it using`path = Application.persistentDataPath + "/StreamingAssets/yourdbfile.db"`
That will only work if you have already copied it to persistent data.
Answer by kaarloew · Apr 11, 2019 at 06:07 AM
You shouldn't store you database to assets folder since it only usable with Unity Editor. If you want to write files to somewhere, use Application.persistentDataPath https://docs.unity3d.com/ScriptReference/Application-persistentDataPath.html
You'll also need to put the file there! This can be done e.g. either outside the app or in it by copying from strea$$anonymous$$gAssets.
Also worth noting that if you're not running on a mobile platform, you're not restricted to that folder. For PC/$$anonymous$$ac standalone applications I usually allow the user to choose what folder to save stuff in.