Android Question android.database.sqlite.SQLiteCantOpenDatabaseException

Rabbit

Member
Licensed User
Longtime User
Hi,

I have this code to create the Database file:
If FirstTime Then
sql1.Initialize(File.DirDefaultExternal, "test1.db", True)
End If



But I get this message:
android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database

Error Code : 1294 (SQLITE_CANTOPEN_ENOENT)



AddManifestText(
<uses-sdk android:minSdkVersion="14" android:targetSdkVersion="26"/>
<supports-screens android:largeScreens="true"
android:normalScreens="true"
android:smallScreens="true"
android:anyDensity="true"/>)
AddManifestText(
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
AddManifestText(
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
)
SetApplicationAttribute(android:icon, "@drawable/icon")
SetApplicationAttribute(android:label, "$LABEL$")
'End of default text.



Please Any Help?

Kinds,
 

Rabbit

Member
Licensed User
Longtime User
This is part of the error:
Caused By : Specified directory or database file does not exist.

even I tried this code:

If FirstTime Then
sql1.Initialize(File.DirInternal, "test1.db", True)
End If

but same issue.
 
Upvote 0

Mahares

Expert
Licensed User
Longtime User
even I tried this code:

If FirstTime Then
sql1.Initialize(File.DirInternal, "test1.db", True)
End If

but same issue.
I tested it with this and your manifest and it worked:
B4X:
If FirstTime Then
        SQL1.Initialize(File.DirInternal, "test1.db", True)
    End If
But if you want to use defaultExternal, you need runtime permissions like this:
B4X:
SQL1.Initialize(rp.GetSafeDirDefaultExternal(""),"test1.db",True)
You may want to uninstall the app and reinstall it.
 
Upvote 0
Top