Creating/Updating Users in Active Directory

  • Thread starter Thread starter Ian Walsh
  • Start date Start date
I

Ian Walsh

Hi,

I'm currently writing a Windows Service that takes user information
from an oracle Database and creates/updates users in an Active
Directory. My problem is that my app eventually runs out of memory.
Basically I'm doing this

DirectoryEntry Base = new
DirectoryEntry("LDAP://path/ou",user,password);
foreach(DataRow row in ds.Tables[0].Rows)
{
mySearcher.Filter = "((sAMAccountName="+row["primaryKey"]+"))";
try
{
if(mySearcher.FindAll().Count==0) //User not found
{
DirectoryEntry NewUser = Base.Children.Add("CN="+row[primaryKey],
"User");
foreach(staticattributes xyz in configObj.staticMappingArray)
{
NewUser.Properties[xyz.ldapAttribute].Value=xyz.staticValue;
}
foreach(mapping xyz in configObj.dataMappingArray)
{
if(row[xyz.dbField].ToString()!="")
{
NewUser.Properties[xyz.ldapAttribute].Value=row[xyz.dbField];
}
}
try
{
NewUser.Properties["displayName"].Value=NewUser.Properties["givenName"].Value+"
"+NewUser.Properties["sn"].Value;
NewUser.CommitChanges();
}
catch(Exception exc)
{
Console.WriteLine(row[0].ToString() + " Invalid Record");
}
}
else //User exists in LDAP
{
}
}
catch(Exception exce)
{
Console.WriteLine(row[0].ToString() + " Invalid Key");
}
}

The memory ramps up on each "if(mySearcher.FindAll().Count==0)" and
doesn't release the memory.

How can I run the app, but make sure it efficiently releases memory so
that the tasks can finish.

Thanks
 
I'm currently writing a Windows Service that takes user information
from an oracle Database and creates/updates users in an Active
Directory. My problem is that my app eventually runs out of memory.

The memory ramps up on each "if(mySearcher.FindAll().Count==0)" and
doesn't release the memory.

There is a known memory bug in .FindOne(), which can cause trouble. It
should be fixed in the Whidbey release (coming up in mid 2005), or you
can alternatively use .FindAll() instead of .FindOne() (there's no
leak in .FindAll() ).

Marc

================================================================
Marc Scheuner May The Source Be With You!
Bern, Switzerland m.scheuner(at)inova.ch
 
Back
Top