Handle SQL errors