[FIX] sql_db: close db connexions before removing them.

Closes #831 aka lp 1322191