This function seems to cry out for an mstore.close() method, and then the mstore can worry about whether it has a connection attribute or a db attribute.