Pergunta

My team is using IIS Express in VS 2013 for debugging, I am getting the following error when querying Active Directory for AD Groups:

An exception of type 'System.Runtime.InteropServices.COMException' occurred in System.DirectoryServices.AccountManagement.dll but was not handled in user code

Additional information: Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.

In the below code, the error is thrown by GetAuthorizationGroups().

Code:

public List<String> GetAllADGroups(String userName)
{

    List<String> groups = new List<String>();

    PrincipalContext ctx = new PrincipalContext(ContextType.Domain, this.Domain, this.LDapUserName, this.LDapPassword);
    UserPrincipal user = UserPrincipal.FindByIdentity(ctx, userName);
    // error on next line
    foreach(Principal group in user.GetAuthorizationGroups().OrderBy(x => x.Name))
    {
        if (group.ContextType == ContextType.Domain && !String.IsNullOrEmpty(group.Name))
        {
            groups.Add(group.Name);
        }
    }
    ctx.Dispose();
    return groups;
}

Since this project is in TFS, I have 3 developers that run this code from their development servers. I am only getting this error on one of the servers. On the server that throws this error; when I run the site from IIS, the code works fine. So it leads me to think the issue is with one of the following:

  1. IIS Express
  2. Server Configuration
  3. VS 2013 Configuration

Any help is appreciated.

Foi útil?

Solução 2

After further investigation, we noticed that the server in question was unable to connect to the Domain Controller, which was causing the problem. What was weird is that this only happened on certain calls to the domain controller. Some calls worked and some didn't. We concluded that it was easier to rebuild the server and start from scratch. With the new server built, we didn't have any issues.

Is this a good answer? Probably not. In this case the server was sick and we euthanized it. Sometimes its easier to start over then spend 3 days trying to figure out the issue (which we did).

Outras dicas

I get the same exception consistently when running GetAuthorizationGroups()

System.Runtime.InteropServices.COMException: 'Multiple connections to a server or shared resource by the same user, using more than one user name, are not allowed. Disconnect all previous connections to the server or shared resource and try again.'

However GetGroups() works fine.

"Euthanizing" the server was not an option so I went with the Token Groups solution from How to get all the AD groups for a particular user? (It is not the accepted answer, at the time of writing it was the third from the top).

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top