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