Program freezing when syncing a ldap database (100+ entries added)
- by djerry
Hey guys,
I'm updating a ldap database. I need to add a list of users to the db. I've written a simple foreach loop. There are about 180 users i need to add, but at the 128th user, the program freezes. I know ldap is really used for querying (fast), and that adding and modifying entries will not go as smooth as a search query, but is it normal that the program freezes while doing this?
I'll post some code just in case.
public static void SyncLDAPWithMySql(Novell.Directory.Ldap.LdapConnection _conn)
{
List<User> users = GetUsers();
int iteller = 0;
foreach (User user in users)
{
if (!UserAlreadyInLdap(user, _conn))
{
TelUser teluser = new TelUser();
teluser.Telephone = user.E164;
teluser.Uid = user.E164;
teluser.Company = "/";
teluser.Dn = "";
teluser.Name = "/";
teluser.DisplayName = "/";
teluser.FirstName = "/";
TelephoneDA.InsertUser(_conn, teluser );
}
Console.WriteLine(iteller + " : " + user.E164);
iteller++;
}
}
private static bool UserAlreadyInLdap(User user, Novell.Directory.Ldap.LdapConnection _conn)
{
List<TelUser> users = TelephoneDA.GetAllEntries(_conn);
foreach (TelUser teluser in users)
{
if (teluser.Telephone.Equals(user.E164))
return true;
}
return false;
}
public static int InsertUser(LdapConnection conn, TelUser user)
{
int iResponse = IsTelNumberUnique(conn, user.Dn, user.Telephone);
if (iResponse == 0)
{
LdapAttributeSet attrSet = MakeAttSet(user);
string dnForPhonebook = configurationManager.AppSettings.Get("phonebookDn");
LdapEntry ent = new LdapEntry("uid=" + user.Uid + "," + dnforPhonebook, attrSet);
try
{
conn.Add(ent);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
return iResponse;
}
Am i adding too many entries at a time???
Thanks in advance.