Added handling of SQL preparation error