My database is not working after build and run !
The sqldatabase is working fine when I run in editor but it does not work after build. This problem started happen after updated the unity to 5.6.0f3 from old one. The sql script is as below. I have tired all I can do.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mono.Data.Sqlite;
using System;
using System.Data;
public class DataStorage : MonoBehaviour
{
public V v;
string conn;
int CheckOk = 0;
private string Answer;
public string Load(string Code)
{
if (Code.Length != 0)
{
CheckOk = 0;
int x = Int32.Parse(Code);
StartCoroutine(Wait());
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlQuery = "SELECT Code,Ans FROM Answers";
//string sqlQuery = "CREATE TABLE IF NOT EXISTS Answers (Code INTEGER NOT NULL PRIMARY KEY, Ans VARCHAR(40))";
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
int CodeM = reader.GetInt32(0);
string Ans = reader.GetString(1);
if (x == CodeM)
{
Answer = Ans;
CheckOk = 1;
break;
}
}
if (CheckOk == 0)
{
Answer = "I don't know what you mean.";
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
else
{
Answer = "I don't know what you mean.";
}
return (Answer);
}
public void Save(string Code,string Ans)
{
int x = Int32.Parse(Code);
Debug.Log(x);
StartCoroutine(Wait());
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open(); //Open connection to the database.
IDbCommand dbcmd = dbconn.CreateCommand();
string sqlAdd = "INSERT INTO Answers VALUES('" + x + "','" + Ans + "')";
dbcmd.CommandText = sqlAdd;
IDataReader reader = dbcmd.ExecuteReader();
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
}
private IEnumerator Wait()
{
conn = "URI=file:" + Application.dataPath + "/StreamingAssets/Memory.db"; //Path to database.
v.SystemLogEditor(conn);
Debug.Log(conn);
yield return conn;
}
}
This is on editor.
This is after build. As you can see, there is no reply log in system log. Please help me.
Comment
Best Answer
Answer by Moesat · May 16, 2017 at 04:27 AM
Oh! It solved! I re-imported the sqlite3.dll file from this link and it works fine. Here the link to get the zip file of Sqlite3.
Your answer
Follow this Question
Related Questions
Moving a file from the project folder to the data directory at runtime 1 Answer
iOS can't connect to SQLite DB 1 Answer
SQLite with JPG blob 0 Answers
login system in unity w/ SQLite 0 Answers
Can sqlite sync with database online? 0 Answers