Modified AttachDatabase function