The electronic structure during the formation of a cyclobutane pyrimidine dimer (CPD) between two thymine bases is investigated using semi-empirical and first-principles approaches. The dimerization of two isolated thymine bases is found to have no barrier or a very small barrier in agreement with previous studies suggesting low photostability of DNA. The well-known high photostability of DNA can only be explained taking other factors into account. We investigate the role of the exciton location in the particular environment. Different model systems, from isolated thymine bases to an oligonucleotide in aqueous solution, are discussed. Analysis of the frontier orbitals allows one to understand the connection between the location of the exciton, the relative orientation of the thymine bases, and the observed reactivity.