Simplify setting database name

Fix how we set and select db name
Fix the db insertion script