If you are not sure how to run code when the application closes, you need to create a blank form and put the connection closing code in the unload event, then open this form in the hidden state when the application opens. When the db closes, the hidden form will be unloaded, thus executing the...