- Home /
Why does SQLite throw InvalidOperationException in Unity 5.3?
Hello,
I am having a little issue trying to use SQLite in Unity 5.3. I have been following the SQLite setup provided here (http://answers.unity3d.com/questions/743400/database-sqlite-setup-for-unity.html) and I have tried to open a sqlite database with the following code:
void Start()
{
string conn = "URI=file:" + Application.dataPath
+ "/trajectoriesDB"; //Path to database.
IDbConnection dbconn;
dbconn = (IDbConnection) new SqliteConnection(conn);
dbconn.Open();
Debug.Log("Database open");
dbconn.Close();
dbconn = null;
}
The problem is that, when the program reaches the line dbconn.Open();, Unity throws the following exception:
InvalidOperationException: Cannot set CommandText while a DataReader is active
I tested in a very simple scene where only this script is running, and I have also double checked that I have all the .dll I need in Assets/Plugins and the database file in Assets/.
I cannot find the root of this problem, since I do not have any DataReader in my code. Has anyone experienced the same problem before?
Thank you in advance!
As far as I can tell, that doesn't appear to be an issue with Unity, but rather with your plugin... I would ask around on the forums for that plugin, and see if they can help. Since it's likely not a Unity-specific issue, you'll probably get better help there, since only a few Unity users will ever use SQLite with Unity.
Answer by Naphier · May 13, 2016 at 06:45 AM
We use SQLite for Unity. Initial setup was originally a bugger, but it works quite well. https://github.com/codecoding/SQLite4Unity3d
they have maximum useless unity examples for they projects and i dont saw api, how u read from existing db? where examples for command and reader? only 3388 lines class
SQLite4Unity3d/Example/Assets/Scripts/ Lots of basic examples. Queries can be done by linq or sql statements. Check out ExistingDBScript.cs
Your answer
Follow this Question
Related Questions
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers
Unity3d c# load or fill dataTable from sqLite local DataBase Error: sqlite3_column_Origin_name 0 Answers