sqLite table not found
I use this code but There error SqliteException: SQLite error no such table: sqlite_stat1 where is problem?
using UnityEngine;
using System.Collections;
using System.Data;
using Mono.Data.Sqlite;
public class PlayerDataManger : MonoBehaviour {
private string connectionString;
// Use this for initialization
void Start () {
connectionString = "URI=file:" + Application.dataPath + "/existing.sqlite";
GetConnectionScore ();
}
void GetConnectionScore ()
{
using (IDbConnection dbConnection = new SqliteConnection (connectionString)) {
dbConnection.Open ();
using (IDbCommand dbCmd = dbConnection.CreateCommand ()) {
//string sqlQuery = "Select * From Person";
string sqlQuery = "Select idx from sqlite_stat1";
dbCmd.CommandText = sqlQuery;
using (IDataReader reader = dbCmd.ExecuteReader ()) {
while (reader.Read ()) {
// Debug.Log (reader.GetString (0));
Debug.Log (5);
}
dbConnection.Close ();
reader.Close ();
}
}
}
}
}
DB
Answer by imramh · Aug 02, 2016 at 09:56 PM
problem solved the proble in extention database name Database must be existing.db
Answer by jgodfrey · May 08, 2016 at 03:28 PM
The db you show in your screen shots is called "existing.db". The db you access in your code is called "existing.sqlite". I can only assume that the "existing.sqlite" db doesn't contain a table named "sqlite_stat1".
when change name to "existing.db". appear problem InvalidCastException: Cannot cast from source type to destination type.$$anonymous$$ono.Data.Sqlite.SqliteDataReader.VerifyType (Int32 i, DbType typ)
table named "sqlite_stat1". exist you can see now
That's a completely different problem. Since you're now getting a cast error from the DataReader, you've successfully accessed your db and the table in question. So, you're original problem is solved it seems...
Regarding the new problem... In the code you posted, I don't see where you're ever attempting to cast anything you've read with the DataReader. Is your code different now?
Your answer
