Add mutex protect to CDatabase's Open/Close method, fix race condition.