add database reconnect code, and create database tables if not found.