SQL Newbee question

JimReid

New Member
Licensed User
Longtime User
I just got Basic4android and love it so far but trying my first sql program. The following statement:

SQL1.Initialize("c:\androidtest", "BooksIveRead", True)

Won't initialize my database. Gives following error:
Error occured

An error has occured in sub: main_activity-create(B4aLine:25)
SQL1.Initialize("c\androidtest","BooksIveRead",True)
android.database.sqlite
SQLiteCantOpenDatabaseException:unable to open database file
Continue?

I read that if the parameter 'True' is specified it would create the database. Is this not accurate? 'False' or blank should only open it.

Any help would be appreciated.


Jim Reid:sign0085:
 

Mahares

Expert
Licensed User
Longtime User
SQL1.Initialize("c:\androidtest", "BooksIveRead", True)

needs to be something like:
B4X:
SQL1.Initialize(File.DirRootExternal & "/androidtest", "BooksIveRead",   True)
or
B4X:
SQL1.Initialize(File.DirInternal & "/androidtest", "BooksIveRead",  True)
or


B4X:
SQL1.Initialize(File.DirDefaultExternal & "/androidtest", "BooksIveRead",   True)
 
Last edited:
Upvote 0

snutting

New Member
Licensed User
Longtime User
Same SQLiteCantOpenDatabaseException Issue

Sorry everyone but I am having the same issue and do not see that there are any other forum threads for this error. android.database.sqlite.SQLiteCantOpenDatabaseException: unknown error (code 14): Could not open database. I am using an SQL example straight from the forum. Do I need to create the test.db somewhere prior to running this code? Is it because I am using an emulator? Here is the code:

Sub Activity_Create(FirstTime As Boolean)
If FirstTime Then
SQL1.Initialize(File.DirDefaultExternal, "test.db", True)​
End If​
End Sub

Thanks!

** UPDATE ** I think I found the fix. I changed the path to File.DirInternal instead of File.DirDefaultExternal and it worked just fine. There was some kind of permissions issue writing to File.DirDefaultExternal is that normal for an emulator?
 
Last edited:
Upvote 0
Top