Finally fixed bug by closing database.