SQLite In Unity Error

筅森魡賤 提交于 2020-01-24 06:22:06

问题


Hi I am trying to insert a SQLite database on my application but when i try and call values from it i am recieving this error

DllNotFoundException: sqlite3
Mono.Data.Sqlite.SQLite3.Open (System.String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool)
Mono.Data.Sqlite.SqliteConnection.Open ()
MuHC.Start () (at Assets/Scripts/TestScripts/MuHC.cs:13)

I have followed this topic here. http://answers.unity3d.com/questions/743400/database-sqlite-setup-for-unity.html

and have the exact same heriarchy and code. (just incase here is my code)

using UnityEngine;
using System.Collections;
using Mono.Data.Sqlite; 
using System.Data; 
using System;

public class MuHC : MonoBehaviour {
    void Start () {
    // Use this for initialization
    string conn = "URI=file:" + Application.dataPath + "/MyAPPA.s3db"; //Path to database.
    IDbConnection dbconn;
    dbconn = (IDbConnection) new SqliteConnection(conn);
    dbconn.Open(); //Open connection to the database.
    IDbCommand dbcmd = dbconn.CreateCommand();





    string sqlQuery = "SELECT QuestionId,QuestionText,InputId,OptionChoiceName,QuestionOptionId,NextQuestion " + "FROM GetQuestions";
    dbcmd.CommandText = sqlQuery;
    IDataReader reader = dbcmd.ExecuteReader();


    while (reader.Read())
    {
        int QuestionId = reader.GetInt32(0);
        string QuestionText = reader.GetString(1);
            int InputId = reader.GetInt32(2);

            Debug.Log( "QuestionId= "+QuestionId+"  QuestionText ="+QuestionText+"  InputId ="+  InputId);
    }

    reader.Close();
    reader = null;
    dbcmd.Dispose();
    dbcmd = null;
    dbconn.Close();
    dbconn = null;




}
}

I have the database in all the correct areas and the name for the db is correct.


回答1:


You have to put the sqlite3.dll in your Assets/Plugins folder.



来源:https://stackoverflow.com/questions/30166155/sqlite-in-unity-error

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!