I created an sqlite database and added tables. This is part of an application I wrote to convert a tab separated file to an sqlite database on the fly. Everything was working, perfectly. However, I now find that the following code doesn’t work:
Var db As New SQLiteDatabase
db.DatabaseFile = SpecialFolder.Desktop.Child(“MyDatabase.sqlite”)
Try
db.CreateDatabase
Catch error As IOException
MessageBox("The database file could not be created: " + error.Message)
End Try
I get the following message:
An exception of class
SQLiteException was not
handled. The application must
shut down.
Exception Message: unable to open
database file
Exception Error Number: 14
I have checked the permissions and I can read/write to the Desktop, but the database is not being created.
I would appreciate any suggestions regarding where to look in order to fix this.
Which version of Xojo? Which OS? Which version of the OS? Does the database already exist at the location? I use the following:
PlanDataDB = New SQLiteDatabase
PlanDataDB.DatabaseFile = PlanDataFolderitem
If PlanDataFolderitem.Exists Then
ConnectOpen
else
ConnectCreateTables
end if
Hi Beatrix,
Thanks
It was working fine until this morning. I have reinstalled Xojo 2023.r2.
I am using a MacBook. I haven’t changed the code in the main program, but the test doesn’t work.
I have the database I created originally, but want to add a table to it. When I run the original code that created the database and added two tables, it no longer works. I tried your approach, and get the same answer:“Unable to open the database” - this is because the database is not created.
16-inch, 2023
Chip Apple M2 Max
Memory 32 GB
Startup disk Macintosh HD
macOS Ventura 13.5.1
For SQLite, CreateDatabase() works exacly as Connect() if the database exists. So, that’s not the problem.
If you check MacError.h you see this:
dsIOCoreErr = 14, /IO Core Error/
For SQlite, we see this:
(14) SQLITE_CANTOPEN
The SQLITE_CANTOPEN result code indicates that SQLite was unable to open a file. The file in question might be a primary database file or one of several temporary disk files.
I have written two functions - one to create a database table from the first line of a tab separated file, the other to add the data to the sqlite database. I wanted to add information from two other TSV files to the existing database. It seems easier to use existing coder rather than write new code to add the tables. The I tried to do that, I found an error.
Having rebooted my computer several times, the problem seems to have resolved itself. If the problem returns, will explore more fully and report back. Thanks for the advice.
Hi,
Thanks for the input - I had no idea that Sqlite created temporary files before creating the actual database. I will spend some time looking at the link you provided. The problem I had was related directly to the inability for db.create to create the database, but has now been resolved. The rate thing about the forum is the sharing knowledge.
Regards to all who are helping to educate me.