Avoid fatal error if doing a DB query after close()

Change-Id: I606a3ec5a45136abf396f86f5a65db209128d5c9
Merge "Avoid fatal error if doing a DB query after close()"