When I build play the game in The editor and build the game through Unity it works fine. When I run the .exe file, the game’s sqlite code does will not work.
using UnityEngine;
using System.Data;
using Mono.Data.Sqlite;
using System.Collections;
using System.Diagnostics;
using UnityEngine.UI;
using System.IO;
public class scoreLoader : MonoBehaviour
{
private string dbName = "game_database";
IDbConnection connection;
public Text scores;
private string current = "";
// Start is called before the first frame update
void Start()
{
//Opens sqlite connectiosn, reads run and time, puts them into scores
connection = new SqliteConnection(string.Format("URI=file:Assets/Streaming Assets/{0}.db", dbName));
connection.Open();
PushCommand(string.Format("CREATE TABLE IF NOT EXISTS \"Scores\" (
\"Run\" INTEGER NOT NULL UNIQUE,
\"Time\" REAL,
PRIMARY KEY(\"Run\")
)"), connection);
scores.text = “This Worked”;
IDataReader dataReader = ReadSavedData();
while (dataReader.Read())
{
scores.text += dataReader["Run"] + " " + dataReader["Time"] + "s
";
}
connection.Close();
}
void PushCommand(string commandString, IDbConnection connection)
{
// Create new command
IDbCommand command = connection.CreateCommand();
// Add your comment text (queries)
command.CommandText = string.Format("{0}", commandString);
// Execute command reader - execute command
command.ExecuteReader();
}
IDataReader ReadSavedData()
{
scores.text = "";
// Create command (query)
IDbCommand command = connection.CreateCommand();
// Get all data in Slot = 1 from coordinates table
command.CommandText = "SELECT * FROM Scores ORDER BY Time LIMIT 7;";
// Execute command
IDataReader dataReader = command.ExecuteReader();
return dataReader;
}
}