主题:[讨论]About AD HELPER
A questiong like this:
While querying AD,how can i use single connection to the LDAP server instead of connect everytime per record
thanks!
the c# like this:
DataTable Staffs = SqlHelper.ExecuteDataSet(SqlHelper.SPBDBConnStr, CommandType.StoredProcedure, "Proc_GetStaffIdForImportAD", null).Tables[0];
if (Staffs != null && Staffs.Rows.Count > 0)
{
for (int i = 0; i < Staffs.Rows.Count; i++)
{
DataRow dr = Staffs.Rows[i];
string staffid = dr.IsNull("StaffID") ? null : dr["StaffID"].ToString();
if (string.IsNullOrEmpty(staffid) || staffid.Length < 4) continue;
DirectoryEntry userEntry = null;
try
{
userEntry = ADHelper.GetUserByAccountSuffix(staffid.Substring(staffid.Length - 4));
}
catch (Exception ex)
{
TraceLoger.Debug(string.Format("Error on search AD info for staff {0}, staff count: {1}.", staffid, i), ex);
continue;
}
if (userEntry != null)
{
string loginId = ADHelper.GetProperty(userEntry, "sAMAccountName");
string firstName = ADHelper.GetProperty(userEntry, "givenName");
string lastName = ADHelper.GetProperty(userEntry, "SN");
string title = ADHelper.GetProperty(userEntry, "Title");
string email = ADHelper.GetProperty(userEntry, "Mail");
string company = ADHelper.GetProperty(userEntry, "Company");
string department = ADHelper.GetProperty(userEntry, "Department");
string rawResidentialNumber = ADHelper.GetProperty(userEntry, "homephone");
string rawMobileNumber = ADHelper.GetProperty(userEntry, "mobile");
string rawDirNumber = ADHelper.GetProperty(userEntry, "telephoneNumber");
}
While querying AD,how can i use single connection to the LDAP server instead of connect everytime per record
thanks!
the c# like this:
DataTable Staffs = SqlHelper.ExecuteDataSet(SqlHelper.SPBDBConnStr, CommandType.StoredProcedure, "Proc_GetStaffIdForImportAD", null).Tables[0];
if (Staffs != null && Staffs.Rows.Count > 0)
{
for (int i = 0; i < Staffs.Rows.Count; i++)
{
DataRow dr = Staffs.Rows[i];
string staffid = dr.IsNull("StaffID") ? null : dr["StaffID"].ToString();
if (string.IsNullOrEmpty(staffid) || staffid.Length < 4) continue;
DirectoryEntry userEntry = null;
try
{
userEntry = ADHelper.GetUserByAccountSuffix(staffid.Substring(staffid.Length - 4));
}
catch (Exception ex)
{
TraceLoger.Debug(string.Format("Error on search AD info for staff {0}, staff count: {1}.", staffid, i), ex);
continue;
}
if (userEntry != null)
{
string loginId = ADHelper.GetProperty(userEntry, "sAMAccountName");
string firstName = ADHelper.GetProperty(userEntry, "givenName");
string lastName = ADHelper.GetProperty(userEntry, "SN");
string title = ADHelper.GetProperty(userEntry, "Title");
string email = ADHelper.GetProperty(userEntry, "Mail");
string company = ADHelper.GetProperty(userEntry, "Company");
string department = ADHelper.GetProperty(userEntry, "Department");
string rawResidentialNumber = ADHelper.GetProperty(userEntry, "homephone");
string rawMobileNumber = ADHelper.GetProperty(userEntry, "mobile");
string rawDirNumber = ADHelper.GetProperty(userEntry, "telephoneNumber");
}