If its in a local function, it probably goes out of scope, with the still open db - the thread that created the db never closed it. Try setting it to null before the function ends and use normal...