Hey All,
So I’ve been working on a function to check for a database and if necessary, programmatically create it. After reading some documentation I realized I wasn’t checking for the database file the right way, I started again this time checking for the db file before doing anything else. The if statement below correctly identifies the presence or absence of a database file, however when I go to set the databasefile value of my sessions database property (Session.DB.databasefile) I get a NilObjectException regardless of what I do to set the property’s value. This makes no sense because AFAIK I have correctly searched for the database file so obviously the object exists but when I go to specify it it’s not there.
I believe this code should work because SQLiteDatabase.DatabaseFile expects a FolderItem type which, as you can see, DatabaseFile is. Further, in accordance with the GetFolderItem documentation, I’m checking the exists property before trying to use the folder item. If the FolderItem Object wasn’t there like the NilObjectException suggests, then my check would have failed and I would have gone to the “else” section of code, but alas, I’m not.
any thoughts?
Other considerations:
- Per this post - I’ve made sure that CheckDB function is not an event of Session.Open, but rather the session itself, so the DB object should persist and work correctly for as long as the session runs.
- The scope of my DB session property is Public so the database should be available to every page of the website.
dim DatabasePath as FolderItem = App.ExecutableFile.Parent.Parent.Child("liffboi.db")
Dim DatabaseFile as FolderItem = GetFolderItem(DatabasePath.AbsolutePath)
if DatabaseFile.Exists = True Then
Session.DB.DatabaseFile = DatabaseFile
MsgBox("Database is found!")
else
MsgBox("Database not found!")
End If