Local Database Access Problem - Unity Android

Hi…

I am working on a Game which needs a Database to read Data, it is working and on Unity Editor and i can read data but when i built for android i’m not able to read database.

So, Where to Put my .db file so i can access it on device and how can i setup which files will be used in Game so unity should not remove during built time.

Can anyone help me on this?

Thanks!!!

I have the same problem. Anyone for help?

StreamingAssets folder.

Only if it is a read-only database, though.

For read-write files, you’ll have to create them in Directory.localFolder.

https://docs.unity3d.com/ScriptReference/Windows.Directory-localFolder.html

Thanks but @neginfinity , I tried these all but still Works on unity editor but, if I complie the Project as an android apk file and load that apk to any android device, I can not read data from the sqlite database.

Also I get a message like ;

ArgumentException: Invalid ConnectionString format for parameter "jar:file://C:/Users/ …

Solved.

I used;

string filepath = Application.persistentDataPath + “/” + “your.database”;

if (!File.Exists(filepath))

{

Debug.LogWarning(“File "” + filepath + “" does not exist. Attempting to create from "” +

Application.dataPath + “!/assets/” + “your.database”);

// if it doesn’t →

// open StreamingAssets directory and load the db →

WWW loadDB = newWWW(“jar:file://” + Application.dataPath + “!/assets/” + “data.sqlite”);

while (!loadDB.isDone) { }

// then save to Application.persistentDataPath

File.WriteAllBytes(filepath, loadDB.bytes);

}

//open db connection

connectionString = “URI=file:” + filepath;

Debug.Log("Stablishing connection to: " + connectionString);

dbConnection = newSqliteConnection(connectionString);

dbConnection.Open();

then I added the database to location;
C:\Users\username\AppData\LocalLow\Your Company name\Your Application name\your.database

then I Created Assets\StreamingAssets\your.database

thats all. Works on android device

2 Likes

how can you add pragmas to this? the way you do it works , but update and insert is super slow and i havent been able to make pragamas work :S

what location sir

daydreamdesign
thanks man you saved my day
it’s working fine

Thank you very much !! T_T :heart: