Next time you get into this situation, note that the highlighted line has not yet been executed. The icon to the left tells you that if you execute this line, there will be an error … but you are not told which one . To be told what the error is, click on the Play button: the line will be executed, the exception will be raised and you will get an explanation.
When working with a database, connect to the database when the application starts, and set db to the open database. If opening the database fails, the display an error message to the user stating that since the database failed to open, the app can’t run.
Each database manipulation should be in a try-catch block to avoid an unhandled exception.