Make SQLite connection better contained.

Thanks @yacc143 for the tip.