Bug fix

Have to open the database before querying it.