opening and closing database