Fixed the database context scoping issue