Search Unity

SqliteException: Unable to open the database file - Ready-made DB Provided To Access

Discussion in 'Android' started by siddharth3322, Jul 5, 2020.

  1. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    This kind of error, I was getting in my Logcat of Android Studio:
    sqlite exception.png

    For a similar exception, I have mostly read all posts from Google but I can't able to find a solution that can work for me. So that I have decided to post a new question over here.

    I was working on working on a small application using the Unity game engine that I target to publish on Android and iOS platforms.

    For this, I require to create a database using SQLite. For the database, I will add all the records within different tables that I need within the application. So mostly I will execute retrieve and update records related queries as per my app need.

    Within my iMac, I have done all the basic setup, and its working properly but when I run the game build within the Android device, I started getting the above exception. So nothing gets executed after that.

    I have placed my database within the Assets folder of the project. Through the following code, I was trying to access it:
    Code (CSharp):
    1. public class SqliteHelper
    2. {
    3.     private const string TAG = "Dysphasia: SqliteHelper:\t";
    4.  
    5.     private const string DATABASE_NAME = "DysphasiaDB.db";
    6.  
    7.     public string db_connection_string;
    8.     public IDbConnection db_connection;
    9.  
    10.     public SqliteHelper()
    11.     {
    12.         db_connection_string = "URI=file:" + Application.dataPath + "/" + DATABASE_NAME;
    13.         Debug.Log("db_connection_string" + db_connection_string);
    14.         db_connection = new SqliteConnection(db_connection_string);
    15.         db_connection.Open();
    16.     }
    17.  
    18.     ~SqliteHelper()
    19.     {
    20.         db_connection.Close();
    21.     }
    22. }
    As I mentioned earlier, within Unity editor all things working properly but in Android device its not.

    I want to publish my game on Android and iOS both platforms so give me some solution that can work on both the platforms. One important point, I don't want to create a database runtime, I want to provide data to the application ready-made.

    I was following this tutorial from first:
    https://medium.com/@rizasif92/sqlite-and-unity-how-to-do-it-right-31991712190

    But in this tutorial, he was creating a database at runtime rather than providing a pre-made database to use.
     
  2. siddharth3322

    siddharth3322

    Joined:
    Nov 29, 2013
    Posts:
    1,049
    Any person who deals with SQLite before please help me into this.