Boh is correct. In the more rural counties, an elected Sheriff has a police function, whereas in more urban counties, a police department has statutory responsibility for police service. The state also authorizes municipalities to establish police departments. The state police functions mainly as a highway patrol in the urban counties, but performs a broader, more generalized police function in more rural counties. The various departments usually have LOAs / SOPs to decide which department has primary responsibility in the various jurisdictions, and some authorities are set forth in the COMARs. You can generally tell who is primary by how the 911 calls are routed. Notably, Baltimore City is an independent jurisdiction, thus is more like a county and has its own elected Sheriff. The state police have limited jurisdiction in the city.
^TL
R, in Frederick County, the sheriff's department is essentially analogous to the county police force in Montgomery County. In the more populous rural (trending suburban) counties like Frederick, the state police operate more like they do in Montgomery or Baltimore counties, focusing more on traffic enforcement vs. day-to-day policing. In smaller counties like Caroline, Talbot et al, both the state police and the sheriff's department respond to calls for service.
TL
R**2: In Loudon County, there is a move to create a police department as the county is growing more urban. A study was performed (by the Sheriff) that found that maintaining the sheriff's department as the primary law enforcement agency was the optimal choice.