1

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.

2
  • 2
    access fails HOW? Commented Apr 13, 2015 at 21:51
  • Well, the video game simply stops run, it 'freezes' Commented Apr 14, 2015 at 20:31

1 Answer 1

2

I finally got it working. The problem was, at least in my case, that Android is based on Linux architecture, so it don't work with .dll libraries, I must use a .so librerie instead. This does not happen with MonoDevelop's own libraries; I guess that makes a translation of these libraries in the build, but not with the external libraries like sqlite3.dll.

I put this .so file into /Assets/Plugins/Android and Unity automatically finds it; in the inspector I must select 'Android' in 'Select platforms for puglin', and 'AR Mv 7' in CPU. I hope this will be useful for others with the same problem.

Since .so library is not on the official website of SQLite, if someone needs it, send me a message and I'll send it by mail.

Sign up to request clarification or add additional context in comments.

2 Comments

So you just replaced Sqlite3.dll by that .so library and the above code worked?
Yes, at least in my case. If it doesn't work for you let me know and I will try to help you.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.