diff --git a/src/mod/applications/mod_callcenter/mod_callcenter.c b/src/mod/applications/mod_callcenter/mod_callcenter.c
index c758147078..9f74d2f9cc 100644
--- a/src/mod/applications/mod_callcenter/mod_callcenter.c
+++ b/src/mod/applications/mod_callcenter/mod_callcenter.c
@@ -562,27 +562,28 @@ char *cc_execute_sql2str(cc_queue_t *queue, switch_mutex_t *mutex, char *sql, ch
 
 	switch_cache_db_handle_t *dbh = NULL;
 
-	if (!(dbh = cc_get_db_handle())) {
-		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
-		return NULL;
-	}
-
 	if (mutex) {
 		switch_mutex_lock(mutex);
 	} else {
 		switch_mutex_lock(globals.mutex);
 	}
 
+	if (!(dbh = cc_get_db_handle())) {
+		switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_ERROR, "Error Opening DB\n");
+		goto end;
+	}
+
 	ret = switch_cache_db_execute_sql2str(dbh, sql, resbuf, len, NULL);
 
+end:
+	switch_cache_db_release_db_handle(&dbh);
+
 	if (mutex) {
 		switch_mutex_unlock(mutex);
 	} else {
 		switch_mutex_unlock(globals.mutex);
 	}
 
-	switch_cache_db_release_db_handle(&dbh);
-
 	return ret;
 }