Switch database name when appropriate on session override.

[ close #2714 ]
[ close #2718 ]