Improved databaseConnection handling