John Lam 1997 — 2026

Multiple user roles and trusted SQL Server Connections

One of the most common questions that I get from advanced students in my ASP.NET class is: “How do I map users to different roles and still use Windows authentication in SQL Server?”

This is actually a pretty difficult problem to solve. In the simplest case, you have two different groups of users. Let’s call them Users and Administrators. You want to restrict access to stored procedures in your SQL Server database by setting the appropriate access control lists (ACL’s) in SQL Enterprise Manager.

Here’s a very rough outline of the process. First, your ASP.NET application needs to map users to the appropriate roles. This in its own right is a fairly complicated topic, so I’ll cover this later. Let’s assume for the time being that you have determined whether the caller is a User or an Administrator.

Next, you need to partition your data access code into two different assemblies; one for Users and the other for Administrators. Your data access code must live in Serviced Components, which are registered as COM+ applications. Finally, you must set the Identity of your COM+ application is. Your User data access assembly will run under one account, and your Administrator data access assembly will run under a different account.

Finally, you set the appropriate ACL’s in SQL Enterprise Manager to allow your User account and your Administrator account in.

There are a whole raft of nasty deployment issues that arise to support this rather innocent looking scenario. I’ll cover the blood and guts of this scenario over the next few days as I build a sample application that solves this problem.Â