Fix BatchSql errors

Backport of #3016 that is binary compatible, and deprecates erroneous
ways of using BatchSql.