Fix duplicate object IDs for command objects.

Fixes #5584
Move the ClearConfigTables function into the DbConnection class.

Refs #5565
Re-use IDs where possible.

Refs #5565