1
Hello, I am trying to add the initials of the company’s employees in the initial parameter of the AD user and when trying to run it returns me the following message:
System.DirectoryServices.DirectoryServicesCOMException: 'O atributo ou valor do serviço de diretório especificado já existe. '
could help me?
// Lê o resultado da query SQL Server
SqlDataReader sdr = scm.ExecuteReader();
Classes.ActiveDirectory AD = new Classes.ActiveDirectory();
// Percorre todos os resultados da query e coloca na ListView
while (sdr.Read())
{
if (!String.IsNullOrEmpty(sdr.GetString(3)))
{
// Realizando a consulta no AD
DirectorySearcher ds = new DirectorySearcher(AD.abreConexaoAD());
// Enviando uma Query para o AD
//ds.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(mail=" + sdr.GetString(3) + "))";
ds.Filter = "(&((&(objectCategory=Person)(objectClass=User)))(sAMAccountName=api.teste))";
// Retorna o resultado
SearchResult rs = ds.FindOne();
if (rs != null)
{
DirectoryEntry directoryEntry = rs.GetDirectoryEntry();
directoryEntry.Properties["initials"].Add(sdr.GetString(0));
//MessageBox.Show(directoryEntry.Properties["sAMAccountName"][0].ToString());
// Salvando as alterações
directoryEntry.CommitChanges();
directoryEntry = null;
}
}
System.Threading.Thread.Sleep(10000);
}
What is the definition of AD?
– Victor Laio
Activedirectory
– Danillo Dars
Isn’t it because you are opening multiple connections with AD? one every while iteration?
– Leandro Angelo
Because it is @Leandroangelo, how do I close the connection? I am beginner and I must be doing something wrong or forgetting something.
– Danillo Dars