I am making a game in Unity where I'd like to use SQLite database for saving readonly data effectivly. Everything is fine in the Editor, but when I build it to windows, it simply couldn't read from it. I tried everything, the path is in the StreamingAssets, I checked that my database is not empty, I have all the neccessary .dll files, I even tried with different versions, from different sources. I also tried that my program, even after build will find a simple txt file next to the database, so it's not matter of the datapath. I must use database, because I need a dozens of data that is readonly and have been written manually. Also I want a flexible and dynamic way to modify my data during playtime. Here is my code, I have multiple functions handling the database, but this the one that's relevant here:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System;
using Mono.Data.Sqlite;
using System.Data;
using Mono.Data;
using System.IO;
public class DataBaseHandler {
public static Record FindRecord(string database, string table, List<string> fields, string feltetel)
{
Record record = new Record(new List<string>());
string conn = "URI=file:" + System.IO.Path.Combine(Application.streamingAssetsPath, database + ".db");
IDbConnection dbconn;
dbconn = (IDbConnection)new SqliteConnection(conn);
dbconn.Open();
IDbCommand dbcmd = dbconn.CreateCommand();
string field = "";
foreach (var item in fields)
{
if (item == fields[fields.Count - 1])
{
field = field + item + " ";
}
else
{
field = field + item + ", ";
}
}
//Debug.Log(field);
string sqlQuery = "SELECT " + field + "FROM " + table + " WHERE " + feltetel;
dbcmd.CommandText = sqlQuery;
IDataReader reader = dbcmd.ExecuteReader();
while (reader.Read())
{
for (int i = 0; i < fields.Count; i++)
{
record.sor.Add(reader.GetString(i));
}
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbconn.Close();
dbconn = null;
return record;
}
}
Record is just a simple class, but I will show you:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class Record
{
public List<string> sor;
public Record(List<string> sor)
{
this.sor = sor;
}
public Record()
{
}
}
Also, I have every neccessary plugins in my folder. Please help me, this drives me crazy, I have been looking for the solution for a week now.