Database closed after using dialog