Modified AtachDatabase function