Fixed view test
Added better diagnostic when SQL query fails