I added a SQLite database to my Unity3D project, all works fine in while I´m working on the Unity Editor, but when I test the game on an Android device the access to the database fails. Has anyone had the same problem and can tell me how to fix it?
An example of the code:
using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite;
using System.Data;
public class DBAccess : MonoBehaviour {
void Start () {
string connectionString = "URI=file:" +Application.dataPath + "/myDataBase"; //Path to database.
IDbConnection dbcon;
dbcon = (IDbConnection) new SqliteConnection(connectionString);
dbcon.Open(); //Open connection to the database.
IDbCommand dbcmd = dbcon.CreateCommand();
string sql = "SELECT firstname, lastname FROM addressbook";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read()) {
string FirstName = reader.GetString (0);
string LastName = reader.GetString (1);
Debug.Log (FirstName + LastName);
}
// clean up
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
}
I read in other threads of this forum that other people have had trouble making the build, isn't my case, I could generate the apk.
I've tested it in two diferents devices with the same result, so I think that it's not a problem of the device.
I am working with MonoDevelop as IDE, the 5.0.1 version of Unity3D and Sqlite 3.8.9, and all this on a laptop with windows 8.1
Thanks in advance.