That’s been the story for Boydton, population 430, in the middle of tobacco country a few miles from the North Carolina border. The prison across from the Microsoft center closed in 2012. A nearby Burlington Industries textile plant that employed more than 2,000 shut in 2002. It was razed in 2012.

Image E.W. Gregory, the head of the local electrical workers’ union, has not had much success finding long-term positions at the data center for his workers. Credit... Chet Strange for The New York Times

In Clarksville, the next town over, a Russell Stover candy factory closed in 2001, taking 700 jobs. Now the building is a data center for the Department of Homeland Security, operated by a small crew from Hewlett Packard Enterprise.

The South Virginia tobacco economy collapsed as Americans cut back on smoking. But in 1999, Virginia used some of the $4.1 billion it received in a settlement with cigarette makers to build high-speed fiber-optic lines throughout the region.

The broadband drew Microsoft, along with some financial perks. Mecklenburg County, which received $2.1 million from the state for the project, has given Microsoft 350 acres and offset personal property taxes by 82.5 percent, according to Wayne Carter, the county administrator.

Initially, Apple, which is building a big cloud center for consumers’ photos and music, wanted the Boydton site, but it went across the border to North Carolina, which promised tax breaks on its data center equipment. Not to be outdone, Virginia passed laws in 2009 and 2010 that exempted sales taxes on things like data center computer servers, software, power generators and chillers to cool all that equipment.

“We’ve had six years of construction work,” said Mr. Carter. That has helped the county, he said, because even temporary workers rent houses, stay in hotels and eat in local restaurants.