Android Question SQLiteCantOpenDatabaseException

wimpie3

Well-Known Member
Licensed User
Longtime User
I'm currently testing an app on several devices.

One of them, an older HTC, crashes with the following error:
android.database.sqlite.SQLiteCantOpenDatabaseException: unable to open database file

This happens in a module on this line:
B4X:
SQL.Initialize(File.DirDefaultExternal, "mydb.db", True)

Since the "true" flag is passed, a new db should be created, but for one reason or another this does not seem to work on this specific device.

What am I missing?
 

DonManfred

Expert
Licensed User
Longtime User
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
Uhmmm... so why would it work on other machines and not on my HTC?

Plus, this is what Erel wrote before:

File.DirRootExternal and File.DirDefaultExternal have a special side effect of adding the STORAGE permission to your manifest file.
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
B4X:
If File.ExternalWritable = True Then
    SQL.Initialize(File.DirDefaultExternal, "mydb.db", True)
Else     
    SQL.Initialize(File.DirInternal, "mydb.db", True)
End If
 
Upvote 0

Pendrush

Well-Known Member
Licensed User
Longtime User
Or you can use this code:
B4X:
SQL.Initialize(DataBasePath, "mydb.db", True)

Sub DataBasePath As String
   If File.ExternalWritable = True Then
     Return File.DirDefaultExternal  
   Else
     Return File.DirInternal
   End If
End Sub
 
Upvote 0

wimpie3

Well-Known Member
Licensed User
Longtime User
This seems to have done the trick... can't I use DirInternal on all occasions and simply leave out the if/then/else?
 
Upvote 0
Top