I have the following code in my application:
using (var database = new Database()) { var poll = // Some database query code. foreach (Question question
You could inherit from the Database class and then override the Dispose() method (making sure to close the db resources), this could then raise a custom event to which you can subscribe in your code.