moved db=null outside trycatch