Android Question (Fixed) Error 14: Could not open db

Emme Developer

Well-Known Member
Licensed User
Longtime User
Hi to all, i'm trying to initialize a db in File.dirInternal (copied from assets) but i got this error:
B4X:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14 SQLITE_CANTOPEN): Could not open database

This is the code i use:
B4X:
If File.Exists(File.DirInternal,DB_NAME) Then
        sqlManager.Initialize(File.DirInternal,DB_NAME,False)
    Else
        File.Copy(File.DirAssets,DB_NAME,File.DirInternal,DB_NAME)
        sqlManager.Initialize(File.DirInternal,DB_NAME,False)
    End If

I think is right because is a shared sub that I use in all my projects... So i don't understand the issue.
File in assets exists. Also in DirInternal.. I know i can use DBUtils to copy file, but i need to understand why i'm getting this error

Thanks to all
 

drgottjr

Expert
Licensed User
Longtime User
normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us...

so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt?
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
normally, i would suspect an issue with DB_NAME (eg, you spelled it wrong or there is a problem with case sensitivity - "A" vs "a"), but in this case if there was a problem with DB_NAME, your tests would have failed and you would have seen a different error. perhaps you did and didn't tell us...

so, if the problem is not with DB_NAME, it would seem to be with the db itself. is it sqlite for sure? did you create it? perhaps it's corrupt?
Now way to have a problem with dbname as i use it in every sub, so i'm sure there is not a problem with mispelling. I'm sure it is SQLite, i created it with SQLliteStudio.
I think it's not corrupted, maybe can be an issue with table

If you copy that database on your computer you can use it?
You can open it?
Yes i can open without any issue
Maybe the db is readonly if you are reading it from assets folder.
I'm trying to read from Dirinternal, not assets. Btw is not readonly
 
Upvote 0

makis_best

Well-Known Member
Licensed User
Longtime User
You are 100% that the name of your database are the same on your database file and everywhere on your code?
Are you sure you don't have any other instance open?
Are you sure that the folder you use is not read only?
Have you try to create another file inside that folder?
 
Last edited:
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
You are 100% that the name of your database are the same on your database file and everywhere on your code?
Are you sure you don't have any other instance open?
Are you sure that the folder you use is not read only?
Have you try to create another file inside that folder?
Yes, 100%
Yes
Yes
Yes

:D
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way?
EDIT:
Can you upload example project?
 
Last edited:
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above.
 
Upvote 0

OliverA

Expert
Licensed User
Longtime User
Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with?
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Pure guess: could it be due to version differences in SQLite?
Usually, from what I observed in the past, if the version on the device is behind you get a syntax error. But, I am guessing too. See this thread:
Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis.
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Did you maybe upload your DB to your phone from PC directly? Trough ADB, FTP or any other way?
EDIT:
Can you upload example project?
I need to try to copy directly as you suggest.

I think you need to upload your project if you can as Pendrush suggested. But, here is another suggestion, as if you need another one, did you try to delete the database from internal and then copy it back to internal from assets and initialize it on firsttime in internal. I hope I am not repeating a recommendation given in the posts above.

I delete all files in internal folder everytime i start the app, to be sure that i will a fresh copy of db (of course only meanwhile i'm in debug)

Pure guess: could it be due to version differences in SQLite? Android is notorious for being behind. Does the desktop version use a feature that the older SQLite can not deal with?
I'm no trying to do nothing, only initialize the db. I don't think the problem is releated to a specific version

I'm attaching a small project that replicates the issue, hope to help someone to find the right way. Thanks to everybody
 

Attachments

  • try.zip
    166.6 KB · Views: 260
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Please MDev, don't let us down. we are all eager to find out what you come up with. Watch, tomorrow Erel will blow by all our suggestions and give him the correct diagnosis.

I'm sure of this, but i'm also sure we can find a solution without the help of Erel ;) (but if he wants to help of course he can :p)
 
Upvote 0

Emme Developer

Well-Known Member
Licensed User
Longtime User
Finally, found the issue!!
The problem is in the DB, i've using a table with a colum named All, and seems that All is a restricted keyword in sqllite so we can't use it as column name

I am quite irritated by the error, could be specified the problem instead of giving error 14, but at the least without this colum all works properly.

Thanks to all for help, and sorry for wasting your time
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
I was just going to post that I deleted the table called: progress and then it worked fine.
Also, you have columns in that table with data type as STRING. I have never seen that before. I usually put TEXT. Is STRING a valid data type in SQLite. Apparently, it is valid. You learn something every day.
 
Last edited:
Upvote 0
Top