From 1015 to 1022, Avicenna was a high official and doctor to the ruler of Hamedan. After the ruler of Hamedan died Avicenna was put in prison. He was released four months later when Hamadan was captured by Alā al-Dawla, the ruler of Isfahan. Alā al-Dawla only captured Hamadan for a short period of time. Avicenna escaped, disguised as a dervish, to Isfahan to work for Alā al-Dawla as a doctor. In 1030, the Ghaznavids attacked Isfahan and some of Avicenna's work was lost and possibly stolen. He died during an attack on the city of Hamedan.