Fix to prevent queries without database

Introduced 'usedb' variable to prevent making queries on application that do not use database