Since 12 September 1687, the city was under Habsburg administration, and was included into the Habsburg Military Frontier. Ottomans attempted to recapture it during the Battle of Zenta on 11 September 1697. However their attack was repulsed. In 1717, the first Orthodox elementary school was opened. Five years later a Roman Catholic elementary school was opened as well. In 1745, Sombor was excluded from the Military Frontier and was included into Bacsensis County. In 1749, Sombor gained royal free city status. In 1786, the city became the seat of Bacsensis-Bodrogiensis County. According to 1786 data, the population of the city numbered 11,420 people, mostly Serbs.