An injection device for injecting liquid medicine to a patient comprises a medicine container (2) an end of which is connectable to a needle (3) and magnetic sensor means (21, 22) for sensing connection of the needle (3) to the medicine container (2).