After her husband allegedly threatened her at riflepoint last spring, Pamela Montgomery went straight to the Prince George's County Courthouse and asked for a domestic-violence restraining order. A judge agreed. He signed a document that required her husband to keep his distance and prohibited him from buying a gun.

But Montgomery may not be as well protected as she thought. A copy of her restraining order wound up in a two-foot-high stack of unprocessed paperwork in the Prince George's Sheriff's Department. For at least three months, clerks failed to enter the document into computer systems that state and federal authorities rely on to make sure guns aren't sold to criminals and others barred from owning firearms.

The same mistake has occurred hundreds of times this year in Prince George's, Calvert and St. Mary's counties, which have the worst records in Maryland when it comes to ensuring that wife beaters, child abusers and others accused of domestic violence are not able to buy guns, documents show.

The three counties have accumulated piles of restraining orders that sit for several weeks or months before they are logged into computer databases, according to public records filed with the Governor's Office of Crime Control and Prevention.

The three counties also flunked a test given last month by the U.S. attorney's office in Baltimore that examined how quickly sheriff's departments and police agencies process restraining orders. By contrast, only six of the state's 23 counties--Caroline, Carroll, Charles, Harford, Montgomery and Worcester--received perfect marks.

Under federal law, people who are the subject of restraining orders are forbidden from buying or possessing firearms. But in Maryland, the names of thousands of people accused of domestic violence are missing from computer databases that the FBI and Maryland State Police use to conduct criminal background checks for gun purchases.

The problem was exposed in September, when a Laurel man allegedly killed his two young children with a handgun that he was allowed to buy because a background check failed to show that he was under a restraining order obtained by his wife.

Pamela Montgomery was luckier. She hasn't been threatened again by her husband. But the 20-year-old mother said she was stunned to learn that a bureaucratic snafu could put her in danger.

"I had no clue," said Montgomery, who has a 3-year-old daughter. "He had pulled a gun on me before. I'm scared of him. If he knew where I lived now, I'd be worried."

It is unclear how many people under restraining orders have been able to buy guns because their names were not entered into law enforcement databases. But Maryland State Police said they have rejected 14 handgun-purchase applications so far this year because background checks discovered the buyers were accused of domestic violence.

Restraining orders are supposed to be entered into law enforcement databases as soon as local police and sheriff's departments receive the paperwork from the courts, according to federal guidelines.

On Oct. 26, the Prince George's Sheriff's Department reported a backlog of 450 restraining orders that had accrued over 3 1/2 months, according to documents filed with the Governor's Office of Crime Control and Prevention.

In Calvert, a much smaller county, the sheriff's department reported a backlog of 40 restraining orders and estimated that it would take a month to clear them. The St. Mary's Sheriff's Department said it had reduced its backlog to a more modest stack--only six orders--and that it would take three days to enter them into the computer.

Some county officials complain that the state's computer system is slow and laborious and estimate that it takes them up to 45 minutes to enter a single restraining order. Some agencies do not assign people to the task full time, so the duties must be fit in with other responsibilities.

Other documents indicate that many restraining orders are not being entered at all.

Last month, the U.S. attorney's office randomly selected several orders from each county in Maryland that had been approved by judges in May and June. It then checked to see if they had been logged in--three or four months later.

Maryland U.S. Attorney Lynne A. Battaglia declined to release the test results, saying she didn't want to "embarrass" law-enforcement agencies that did poorly. But a copy obtained elsewhere by The Washington Post shows that Prince George's and St. Mary's scored the worst marks in the state.

None of the restraining orders sampled from the two counties--10 in Prince George's and five in St. Mary's--was recorded in law-enforcement databases. Calvert did only slightly better; just one of five orders selected from that county was entered.

The only other county in Maryland that posted such a high percentage of missing entries was Somerset, where none of the three restraining orders that were selected could be found.

Statewide, one-third of the 138 restraining orders selected for the study had not been entered after three months, according to the test results.

"This is yet another indicator of how woefully neglectful we are to the needs of battered women," said Carole Alexander, executive director of the House of Ruth in Baltimore, an advocacy group for battered women.

"If these women get past the hurdles of going to court, they get this piece of paper that they truly believe is going to solve their problem. But if a protective order is not entered or enforced, it's a worthless piece of paper."

Law-enforcement officials in Prince George's, St. Mary's and Calvert acknowledged that problems had been allowed to fester but said they were pushing hard to eliminate the backlogs.

Sgt. Bill Ament, spokesman for the Prince George's Sheriff's Department, said several employees were recently assigned to work overtime to reduce the backlog. He predicted that it would be gone by the end of the month.

"I think everyone was aware we were falling behind in entering the orders into the system, but I don't think anyone was aware we had fallen that far behind," Ament said. "We treat it as a serious issue. It was a potentially dangerous situation in that if someone had attempted to purchase a weapon, they may have been able to do so."

In Calvert, both the sheriff's department and the county's 911 dispatch center are responsible for processing restraining orders.

Robert Short, Calvert's public safety director, said three employees working overtime this week were able to clear a pile of 38 orders that had stacked up. "Corrective action has been taken," he said. "I can assure you it won't happen again."

St. Mary's officials did not return phone calls. Lynn Fitrell, executive director of the St. Mary's Women's Center, said the local sheriff's department is plagued by computer problems and a lack of staff.

Fitrell said the delays are dangerous because domestic abusers are most likely to retaliate against their accusers--and possibly try to buy a gun--in the first few days after a restraining order is filed.

"That's probably the most volatile time," she said. "That's when the anger and the repercussions come out, most assuredly. We talk to these victims every day, and their immediate concerns are, 'Hey, I'm afraid he's going to come after me with a gun.' "

Other counties in Maryland have also had trouble keeping up with restraining orders.

Allegany and Washington counties reported in late October that it would take them a full month of extra work to clear their restraining-order backlogs, according to documents filed with the Governor's Office of Crime Control and Prevention. Anne Arundel and Howard counties reported having backlogs in the past but said they had caught up recently.

Results from the test by the U.S. attorney's office show that 17 counties and Baltimore City had problems processing restraining orders on a timely basis.

The test was administered shortly after Richard Wayne Spicknall II, of Laurel, was arrested and charged in the shooting deaths of his 3-year-old daughter and 2-year-old son on Sept. 9.

Authorities say Spicknall had bought a Smith & Wesson 9mm handgun at a College Park pawnshop one week before, though he should have been prohibited from purchasing firearms because his wife had obtained a restraining order against him in December 1998.

Howard County officials said Spicknall's restraining order was entered into law enforcement databases on the day it was granted, but that it was later mistakenly removed by a clerk who misinterpreted its wording. As a result, Spicknall was able to pass a criminal background check when he applied to buy the handgun.

Since then, many counties have been working feverishly to whittle down stacks of unprocessed restraining orders and to fix other flaws.

The Frederick County Sheriff's Office recently discovered that it needs to correct 130 restraining orders that had been entered after an audit showed they contained errors.

"Because of the seriousness of this, I want to pull all of them and say, 'Are they right?' " said Lt. J. J. Smith, who is in charge of the project. "I don't want any mistakes to be made. Lord forbid, I never want to see another Spicknall case again. It was horrible what happened."