0

I have a preloaded db file, which is present in c drive in my system. If I connect that db file to unity project and try to get data from tables it didn't get any data and I am not getting any exceptions also. If I open this db file (which is present in c drive) with sqlite admin software it shows data in tables. Please suggest any idea, what I am missing. Here is the code I am using for connecting database to my unity project.

   Public void OpenDatabase()
   {
     var dbfileName = "Testuser.db"

     var _filePath = File.GetFullPath(dbfileName);

     var _connectionString = "URI=file:" + _filePath;

     dbcon = new SqliteConnection(_connectionString);

     dbcon.Open();
   }

When I am trying to create and read db file in the following manner working well.

Working code :

     Public void OpenDatabase()
     {

       var _filePath = Application.PersistanceDataPath + "/" + "owndbfile.db";

       if (!File.Exists(_filePath))
        {                                              
            WWW loadDB = new WWW("jar:file://" + Application.PersistanceDataPath + "!/assets/" + "owndbfile.db");

            while (!loadDB.isDone) { }

            // then save to Application.persistentDataPath

            File.WriteAllBytes(_filePath, loadDB.bytes);
        }

       var _connectionString = "URI=file:" + _filePath;

       dbcon = new SqliteConnection(_connectionString);

       dbcon.Open();
   }

Please suggest any idea for reading data from tables, if db file is present in one of the drive in a system instead of a present in "application persistance" path.

Deepak
  • 545
  • 1
  • 12
  • 36
  • Replace `WWW("jar:file://" + Application.PersistanceDataPath + "!/assets/" + "owndbfile.db");` **with** `WWW("YourDatabasePathOnAnotherDrive");` – Programmer Oct 31 '18 at 13:07
  • Okay Thank you., I will try and tell you result. – Deepak Oct 31 '18 at 13:14
  • I have tried with that but I getting 0 bytes. Here is the code I have tried => WWW loadDB = new WWW(DatabasePathOnAnotherDrive); – Deepak Oct 31 '18 at 13:23
  • It can't find the file. What's the value of `DatabasePathOnAnotherDrive`? Use `File.Exists` to check if `DatabasePathOnAnotherDrive` even exist – Programmer Oct 31 '18 at 13:25
  • Yes I have write the code for checking file exist or not but it gives true => var fileFullPath = File.GetFullPath(filename); If(File.Exist(fileFullPath)){} – Deepak Oct 31 '18 at 13:32
  • Sorry I have checked once again, it shows file not exit. how can get file path which is present in downloads folder. – Deepak Oct 31 '18 at 13:40
  • Read the comment from my [other](https://stackoverflow.com/questions/53076233/how-to-retrieve-data-from-sqlite-db-in-unity-where-db-file-is-present-in-downloa?noredirect=1#comment93062702_53076233) post. By the way, wouldn't this be better if you let the user select the file with a file picker then use the path? There are many file pickers on the asset store or you can make your own. – Programmer Oct 31 '18 at 13:44
  • I have move my file to my project folder location and checking that file is exist or not. it retur true but still I am getting 0 bytes from new www(filefullpath). – Deepak Oct 31 '18 at 14:00
  • Make sure you don't have the database file open in another program (like your admin software) at the same time. – Leo Bartkus Oct 31 '18 at 15:44

0 Answers0