My application is running fine from within the IDE. I’m using SQLite for the database. After ‘building’ the application, when I double click the exe, i’m getting the error:
Database does not exit. This application will now close - note: ‘exit’ is the exact spelling. i believe it should be ‘exist’.
After clicking Okay i get the following:
Database error: 0
Operation cannot be completed because the database is closed.
Then the application opens. But trying to get data results in the Database error: 0 again.
It sounds like the database you’re trying to access is not being referenced correctly by your getfolderitem statement - if no path has been given then just make sure your database is in the same folder as the app build or wherever you’ve put it or put in an absolute path like getfolderitem("G:\myDb…) then the app know where to expect the db. Also you need to connect to open the db
if db.connect()=false then
msgbox "Can't connect - to database "
end if
after the getfolderitem statement will stop the app crashing…maybe use a dialogue to locate the db instead.
Here’s my current code:
[code // Set Database File #if DebugBuild then
rakDataDB.databaseFile = GetFolderItem("").Parent.Child(“rakTestData.db”) #else
rakDataDB.databaseFile = GetFolderItem(“rakTestData.db”) #endif
// Connect to the database
If rakDataDB.databaseFile.exists = True then
// The database file already exists, so we want to connect to it.
If rakDataDB.Connect() = False then
// there was an error connecting to the database
Beep
MsgBox "Database Error: " + Str(rakDataDB.ErrorCode) + EndOfLine + _
EndOfLine + rakDataDB.ErrorMessage
Quit
Return
End if
Else
// The database file does not exist so we want to create a new one.
// The process of creating a database will establish a connection to it
// so there isn’t a need to call Database.Connect after we create it.
MsgBox “Databse does not exit. The application will now close.”
WindowMain.Close()
End if][/code]
[quote=19726:@Robert Kamarowski]MsgBox “Databse does not exit. The application will now close.”
WindowMain.Close()[/quote]
This the part of you code that is displaying your message. Which indicates that the DB file does not exist. Perhaps you should also call “Quit” here rather than closing WindowMain like that?
I’m curious what makes you expect that there would there be one ?
Your code to open it is looking for a file next to the application
#if DebugBuild then
rakDataDB.databaseFile = GetFolderItem("").Parent.Child("rakTestData.db")
#else
rakDataDB.databaseFile = GetFolderItem("rakTestData.db")
#endif
You either need to create one or have one already there when you run your application.
You can adjust your code to create the database if its missing
// Set Database File
#if DebugBuild then
rakDataDB.databaseFile = GetFolderItem("").Parent.Child("rakTestData.db")
#else
rakDataDB.databaseFile = GetFolderItem("rakTestData.db")
#endif
If rakDataDB.databaseFile is nil then
// you have a big problem as this should not happen
// deal with the error
MsgBox "Not sure what's wrong with locating the database. The application will now close."
Quit
end if
// Connect to the database
If rakDataDB.databaseFile.exists = True then
// The database file already exists, so we want to connect to it.
If rakDataDB.Connect() = False then
// there was an error connecting to the database
Beep
MsgBox "Database Error: " + Str(rakDataDB.ErrorCode) + EndOfLine + _
EndOfLine + rakDataDB.ErrorMessage
Quit
Return
End if
Else
// The database file does not exist so we want to create a new one.
// The process of creating a database will establish a connection to it
// so there isn't a need to call Database.Connect after we create it.
if not rakDataDB.CreateDatabase then
// oh oh we cant even create it !
MsgBox "Can't create database. The application will now close."
Quit
end if
// ok we created the database file now create the tables etc
// THIS IS SOMETHING YOU HAVE TO WRITE !!!!!
End if
The database has been created. When I moved it to the directory with the executable it worked. I thought sqlite was an embedded database, meaning it was included in the exe.
99.9% of the time they need to be readable & writeable so we cannot put it in the exe as the OS and virus checkers would prevent that or flag it as virus-like behaviour
SQLite is an embedded database. But embedded means the database engine is embedded in the app, not the database file.
In this day and age, apps should not be modified by themselves. OS permissions would likely prevent that, but even if they didn’t it would likely trigger virus scanners as Norman mentioned.
You should store the database file elsewhere. Your own folder within SpecialFolder.ApplicationData is usually a safe place.