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
 

Emme Developer

Well-Known Member
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.
Yes, the column All is in progress, i discovered the issue when i tried to delete progress and it worked fine as you write.
Usually I also put text, this time I put string out of carelessness, I've resumed mobile developing and sqllite after 2 years without doing nothing. But right point of view, the difference is here https://stackoverflow.com/questions/11938401/difference-between-text-and-string-datatype-in-sqlite
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
Lessons Learned from this thread (at least for me)
1. It is better to create the database and its tables via B4X code rather than create it via a PC program and load it to device. The exact error would have been displayed in the log as opposed to a an ambiguous error like error 14 generated when the database was created on the PC.

2. It is most generally advised as in a case similar to this thread to include a copy of the database or better yet the project for other members to help debug as opposed to making others write a multitude of guesses that prolong the thread

3. Not a good idea to name a table name or column ‘All’ as it is a reserved word in SQLite among many others. But if you insist on using ‘All’ in a column name add, say 1 to it like this: ‘All1’

4. Not to use STRING as data type but preferably use TEXT, although STRING can be used and does not generate an error, but with a cautionary measure.
 
Upvote 0
Top