• Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by siddharth3322 · Jul 05, 2020 at 08:44 AM · androiddatabasesqlitepersistentdatapathdatapath

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

This kind of error, I was getting in my Logcat of Android Studio: alt text

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:

 public class SqliteHelper
 {
     private const string TAG = "Dysphasia: SqliteHelper:\t";
 
     private const string DATABASE_NAME = "DysphasiaDB.db";
 
     public string db_connection_string;
     public IDbConnection db_connection;
 
     public SqliteHelper()
     {
         db_connection_string = "URI=file:" + Application.dataPath + "/" + DATABASE_NAME;
         Debug.Log("db_connection_string" + db_connection_string);
         db_connection = new SqliteConnection(db_connection_string);
         db_connection.Open();
     }
 
     ~SqliteHelper()
     {
         db_connection.Close();
     }
 }

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: SQLite and Unity: How to do it right

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

sqlite-exception.png (46.9 kB)
Comment
Add comment · Show 11
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image xxmariofer · Jul 06, 2020 at 11:15 AM 0
Share

Hello, i have never used the SqliteConnection class, but almost sure you cant simply pass him the stream assets path

the content inside the strea$$anonymous$$g assets folder gets copied inside the apk, and you need to use the WWW or the UnityWebRequest classes to get the DB and use the downloaded content as DB

avatar image siddharth3322 xxmariofer · Jul 06, 2020 at 01:38 PM 0
Share

do you mean by the default database file not present within the strea$$anonymous$$g assets folder? when we install the game build. We require to manually copy that file over the strea$$anonymous$$g assets folder.

avatar image xxmariofer siddharth3322 · Jul 06, 2020 at 01:58 PM 0
Share

No, no. What i mean is that the files DO get copied, but they are located INSIDE a jar file, so since they are inside a jar file, you cant access it simply using the path to the file. "Similar" to how yoou cant access a file inside a zip. Because they are inside the jar you need to use the UnityWebRequest class to retrieve the DB,

should be something like this, this is just pseudocode it is not tested

     string path = Application.strea$$anonymous$$gAssetsPath;

     path += "/" +  DATABASE_NA$$anonymous$$E;

     using (UnityWebRequest www = UnityWebRequest.Get(path))
     {
         yield return www.SendWebRequest();
         File.WriteAllText(Application.persistentDataPath + "DATABASE_NA$$anonymous$$E ", www.downloadHandler.text);
      }

      db_connection = new SqliteConnection(Application.persistentDataPath + "DATABASE_NA$$anonymous$$E ");
      db_connection.Open();



Show more comments

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Welcome to Unity Answers

If you’re new to Unity Answers, please check our User Guide to help you navigate through our website and refer to our FAQ for more information.

Before posting, make sure to check out our Knowledge Base for commonly asked Unity questions.

Check our Moderator Guidelines if you’re a new moderator and want to work together in an effort to improve Unity Answers and support our users.

Follow this Question

Answers Answers and Comments

286 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Help with SQLite for Android Errors in Unity3D? 1 Answer

how to access and modify my existing database made by DB browser for SQLite in unity after build 0 Answers

why sqlite can't conneted after build in PC (.exe) 0 Answers

[Android - Data save issues] Does the 'install location' determine the location of persistentDataPath? 1 Answer

how to use database in unity for developing android games? 0 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges