数据库无法在android c#unity上运行

数据库无法在android c#unity上运行,c#,database,unity3d,C#,Database,Unity3d,我正在用C#在Unity中开发一款游戏,在使用在线数据库或桌面时表现不错,但在android上无法运行。我使用了Sqlite4Unity3D插件和代码,并在网上查看了一下,但不明白为什么不起作用 它在个人电脑上可以工作,但在安卓系统上,它根本不做应该做的事情 我有以下代码: using UnityEngine; using System.Collections; using System.Collections.Generic; using System.Data; using M

我正在用C#在Unity中开发一款游戏,在使用在线数据库或桌面时表现不错,但在android上无法运行。我使用了Sqlite4Unity3D插件和代码,并在网上查看了一下,但不明白为什么不起作用

它在个人电脑上可以工作,但在安卓系统上,它根本不做应该做的事情

我有以下代码:

     using UnityEngine; 
using System.Collections;

using System.Collections.Generic;
using System.Data;
using Mono.Data.Sqlite;

using System.IO;
公共类BancoDeDados:单一行为 {

当我在编辑器中运行它时,它工作得很好,但当我在Android上导出它时,它就不工作了


有人能帮我吗?

我不得不使用Application.persistentDataPath而不是Application.dataPath,它成功了!

我只能假设数据库的路径不正确。你可以尝试在屏幕上的文本字段中显示conn变量,然后在设备上检查该路径。就是这样!我在线检查了,他们告诉我如果您在编辑器之外运行,请使用不同的路径!感谢您!很高兴它有所帮助。
private string conn;
private IDbConnection dbconn;
private IDbCommand dbcmd = null;
private IDataReader reader;


private string CADASTRARFASE = "UPDATE Fases SET Fase";
private string selectTodosFases = "SELECT * FROM Fases";
private string inserirFase = "INSERT  INTO Fases (Fase1) VALUES ('false');";
// Use this for initialization
void Start ()
{
    conecta ();
    dbcmd.CommandText = selectTodosFases;
    IDataReader reader = dbcmd.ExecuteReader();
    if (!reader.Read()) {
        reader.Close ();
        reader = null;
        dbcmd.CommandText = inserirFase;
        IDataReader reader2 = dbcmd.ExecuteReader();
    }

    desconecta ();
}


public int checaIsTrue() {
    conecta (); 
    dbcmd.CommandText = selectTodosFases;
    IDataReader reader = dbcmd.ExecuteReader();
    if (!reader.Read()) {
        return 1;
        desconecta ();
    } else {
        desconecta ();
        return 0;
    }


}

// Update is called once per frame
void Update ()
{

}



public void cadastraFase(string i) {
    conecta ();
    string cad = CADASTRARFASE + i + "='true';";
    dbcmd.CommandText = cad;
    reader = dbcmd.ExecuteReader();

    desconecta ();
}

private void desconecta() {

    dbcmd.Dispose();
    dbcmd = null;
    dbconn.Close();
    dbconn = null;
}


private void conecta() {
    conn = "URI=file:" + Application.dataPath + "/projetomuseu.s3db"; //Path to database.

    dbconn = (IDbConnection) new SqliteConnection(conn);
    dbconn.Open(); //Open connection to the database.

    dbcmd = dbconn.CreateCommand();
    string sqlQuery = "CREATE TABLE IF NOT EXISTS [Fases] (\n[Fase1] BOOLEAN DEFAULT 'false' NULL,\n[Fase2] BOOLEAN DEFAULT 'false' NULL,\n[Fase3] BOOLEAN DEFAULT 'false' NULL,\n[Fase4] BOOLEAN DEFAULT 'false' NULL,\n[Fase5] BOOLEAN DEFAULT 'false' NULL,\n[Fase6] BOOLEAN DEFAULT 'false' NULL,\n[Fase7] BOOLEAN DEFAULT 'false' NULL,\n[Fase8] BOOLEAN DEFAULT 'false' NULL,\n[Fase9] BOOLEAN DEFAULT 'false' NULL\n)";
    dbcmd.CommandText = sqlQuery;
    reader = dbcmd.ExecuteReader();


    reader.Close();
    reader = null;

    sqlQuery = "CREATE TABLE IF NOT EXISTS [Colecionaveis] (\n[Co1] BOOLEAN DEFAULT 'false' NULL,\n[Co2] BOOLEAN DEFAULT 'false' NULL,\n[Co3] BOOLEAN DEFAULT 'false' NULL,\n[Co4] BOOLEAN DEFAULT 'false' NULL,\n[Co5] BOOLEAN DEFAULT 'false' NULL,\n[Co6] BOOLEAN DEFAULT 'false' NULL,\n[Co7] BOOLEAN DEFAULT 'false' NULL,\n[Co8] BOOLEAN DEFAULT 'false' NULL,\n[Co9] BOOLEAN DEFAULT 'false' NULL,\n[Co10] BOOLEAN DEFAULT 'false' NULL,\n[Co11] BOOLEAN DEFAULT 'false' NULL,\n[Co12] BOOLEAN DEFAULT 'false' NULL,\n[Co13] BOOLEAN DEFAULT 'false' NULL,\n[Co14] BOOLEAN DEFAULT 'false' NULL,\n[Co15] BOOLEAN DEFAULT 'false' NULL,\n[Co16] BOOLEAN DEFAULT 'false' NULL,\n[Co17] BOOLEAN DEFAULT 'false' NULL,\n[Co18] BOOLEAN DEFAULT 'false' NULL\n)";
    dbcmd.CommandText = sqlQuery;
    reader = dbcmd.ExecuteReader();

    reader.Close();
    reader = null;



    sqlQuery = "CREATE TABLE IF NOT EXISTS [Biografias] (\n[Bio1] BOOLEAN DEFAULT '''false''' NULL,\n[Bio2] BOOLEAN DEFAULT '''false''' NULL,\n[Bio3] BOOLEAN DEFAULT '''false''' NULL,\n[Bio4] BOOLEAN DEFAULT '''false''' NULL,\n[Bio5] BOOLEAN DEFAULT '''false''' NULL,\n[Bio6] BOOLEAN DEFAULT '''false''' NULL,\n[Bio7] BOOLEAN DEFAULT '''false''' NULL,\n[Bio8] BOOLEAN DEFAULT '''false''' NULL,\n[Bio9] BOOLEAN DEFAULT '''false''' NULL,\n[Bio10] BOOLEAN DEFAULT '''false''' NULL,\n[Bio11] BOOLEAN DEFAULT '''false''' NULL,\n[Bio12] BOOLEAN DEFAULT '''false''' NULL,\n[Bio13] BOOLEAN DEFAULT '''false''' NULL,\n[Bio14] BOOLEAN DEFAULT '''false''' NULL,\n[Bio15] BOOLEAN DEFAULT '''false''' NULL,\n[Bio16] BOOLEAN DEFAULT '''false''' NULL,\n[Bio17] BOOLEAN DEFAULT '''false''' NULL,\n[Bio18] BOOLEAN DEFAULT '''false''' NULL\n)";
    dbcmd.CommandText = sqlQuery;
    reader = dbcmd.ExecuteReader();
    reader.Close();
    reader = null;

}