Android Question Sqlite Could not open database

Brad Henderson

Member
Licensed User
Hello
I have a problem when trying to create an sqlite database. The database name is to be in the form "Name - date" like: "BradHen - 17022024.db"
When I use this code:
B4X:
Dim MyPath as String = "/storage/emulated/0/Android/data/b4a.appname/files"
Dim TodaysdbSql As SQL
Dim NewOpCode As String = "TomHanks"
Dim DateString As String =  DateTime.Date(DateTime.Now)
Dim NewFileName As String =NewOpCode & " - " & DateString & ".db"
Todaysdb=NewFileName
TodaysdbSql.Initialize(MyPath,Todaysdb,True)
I get the error: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database

However if I use this code:
B4X:
Dim MyPath as String = "/storage/emulated/0/Android/data/b4a.appname/files"
Dim TodaysdbSql As SQL
Todaysdb = "TomHanks - 17022024.db"
TodaysdbSql.Initialize(MyPath,Todaysdb,True)

it works??

Am I missing something in the creation of "NewFileName" in the first example?

Your help is appreciated.
Brad
 

LucaMs

Expert
Licensed User
Longtime User
Last edited:
Upvote 0
Solution

Brad Henderson

Member
Licensed User
Sorry for wasting anyone's time, I forgot about the slashes is the date format.
So the file name appeared as "TomHanks - 17/02/2024.db" which obviously won't work.
But getting rid of the slashes I get "TomHanks - 17022024.db" which worked.

Thanks Lucas when I printed the Log(Todaysdb) the mistake was clear.
 
Upvote 0

PoppaBart

Member
Hello
I have a problem when trying to create an sqlite database. The database name is to be in the form "Name - date" like: "BradHen - 17022024.db"
When I use this code:
B4X:
Dim MyPath as String = "/storage/emulated/0/Android/data/b4a.appname/files"
Dim TodaysdbSql As SQL
Dim NewOpCode As String = "TomHanks"
Dim DateString As String =  DateTime.Date(DateTime.Now)
Dim NewFileName As String =NewOpCode & " - " & DateString & ".db"
Todaysdb=NewFileName
TodaysdbSql.Initialize(MyPath,Todaysdb,True)
I get the error: android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 1294): Could not open database

However if I use this code:
B4X:
Dim MyPath as String = "/storage/emulated/0/Android/data/b4a.appname/files"
Dim TodaysdbSql As SQL
Todaysdb = "TomHanks - 17022024.db"
TodaysdbSql.Initialize(MyPath,Todaysdb,True)

it works??

Am I missing something in the creation of "NewFileName" in the first example?

Your help is appreciated.
Brad
If you Log(NewFileName) in the 1st example, you will get something like 02/17/2024.db.

I think the forward slashes / are the problem. B4X may be treating them as a file path.

Try using NewFileName = NewFileName.Replace("/","") to remove them
 
Upvote 0
Top