The Air Force is investigating why it didn't send Devin Kelley's court-martial and conviction for domestic violence to the FBI database used to approve gun buyers.

If the database had included information about Kelley's criminal record, the man responsible for gunning down 26 people in a Texas church would have not been allowed to purchase a gun from a store.

"Federal law prohibited him from buying or possessing firearms after this conviction," Ann Stefanek, an Air Force spokeswoman, said in a statement. The Air Force has asked the Defense Department's inspector general to investigate the lapse.

Kelley pleaded guilty in 2012 to beating his first wife and assaulting his stepson "with a force likely to produce death or grievous bodily harm," according to records released by the Air Force. He received a bad-conduct discharge in 2014 after he served a year in a military brig near San Diego.

Officials at the base where he was stationed and was convicted, Holloman Air Force Base in New Mexico, should have sent his record to the FBI's criminal history database, Stefanek said. It feeds the national database gun sellers use to vet customers.

After his discharge, Kelley bought four guns, three of which were recovered from the crime scene in Sutherland Springs, where he opened fire on First Baptist Church. He appears to have passed all the checks required of gun purchasers.

"There was no disqualifying information entered into the database," Fred Milanowski, special agent-in-charge of the Houston division of the Bureau of Alcohol, Tobacco and Firearms, said earlier Monday.

According to the ATF, Kelley had purchased two guns in Colorado and two in Texas since 2014. The two in Texas were purchased at an Academy Sports store.

Gun sellers forward a potential buyer’s name and paperwork to the FBI’s National Instant Criminal Background System, also known as NICS. The system checks state and federal criminal histories.

If the would-be buyer’s application, which includes a fingerprint check, produces any disqualifying information, the sale would be delayed to give the FBI more time to investigate. If the agency confirmed the disqualifying information, the purchase would be denied.

Devin Kelley

(Texas Department of Public Safety)

All branches of the military are supposed to report convictions and dishonorable discharges to the FBI to include in the database. While Kelley's bad-conduct discharge would not have banned him from owning a gun, his conviction while serving should have, the Air Force said.

One official with knowledge of how the database system works told The Dallas Morning News that the military has a history of not disclosing conviction information to the FBI. That information is used not only by law enforcement but by health and child-care licensing agencies.

“If you spend spend 12 months in jail or prison for a criminal offense that is nowhere to be found in state or FBI records, what is anybody supposed to do?” he said.

Both the military conviction and the bad-conduct discharge should have prevented the 26-year-old Kelley from getting a security-guard license in Texas. But the Texas Department of Public Safety approved his license last summer. If Kelley had disclosed he had been in the military, the agency would have asked him for his discharge paperwork that would have shown his bad-conduct discharge.