473,388 Members | 919 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ADODB OleDbDataAdapter different count of rows from Active Directory

I have a class which reads Groups and Users from ActiveDirectory. The
Problem is, that i have about 10000 rows as product. When I am trying to
read the "memberOf" Objects out of this field i get allways different
count of rows.

If anybody knows something about this kind of problem, I would
appreciate any help.


Here is the class:

using System;

using System.DirectoryServices;

using ActiveDs;
using System.Data;
using System.Globalization;

using System.Windows.Forms;
using System.Threading;

using ADODB;
using System.Data.OleDb;

using com.pironet.asp.rtool.database;

namespace com.pironet.asp.rtool.user
/// <summary>
/// Class for collecting informations
/// about user in ActiveDirectory
/// </summary>
public class AspGroupUserAD
private string dom = string.Empty;

DataTable adTable;
DataTable dbTable;

private string searchFilter = " WHERE objectClass = 'user' ";

/// <summary>
/// Empty
/// </summary>
public AspGroupUserAD()

private void Init()
DirectorySearcher DSESearcher = new DirectorySearcher();
string RootDSE = DSESearcher.SearchRoot.Path;

string ldapCompany= "OU=Hosting,";
this.dom = RootDSE.Insert(7, ldapCompany );


public DataTable DataTable
get{ return dbTable ;}
set{ dbTable = value;}

private void WaitForAdTable(int count)

#region get all data of the user from active directory

/// <summary>
/// Rekursiver Durchlauf ohne Filter
/// </summary>
/// <param name="entry"></param>

public void PopulateAdTable()
string ldapUser= dom;

ADODB.Connection conn=new ADODB.Connection();
ADODB.Recordset rs=new ADODB.RecordsetClass();

ADODB.Command cmd=new ADODB.Command();


OleDbDataAdapter daUsers=new OleDbDataAdapter();

string selectUser = "SELECT sn, objectGUID, msExchMailboxGuid,
lastLogon, userAccountControl, distinguishedName, memberOf FROM '" +
ldapUser + "'" + searchFilter +" ORDER BY sn ASC";

rs.Open( selectUser, conn, CursorTypeEnum.adOpenDynamic,
LockTypeEnum.adLockReadOnly, 1);

DataSet userDataSet = new DataSet("groupuser");

daUsers.Fill(userDataSet, rs,"groupuserAD");

this.adTable = userDataSet.Tables["groupuserAD"];




#region prepare for import in database
private void CreateDBUserTable()
this.dbTable = new DataTable("groupuserDB");

dbTable.Columns.Add("countID",System.Type.GetType( "System.Int64"));
dbTable.Columns.Add("userGUID", System.Type.GetType("System.String"));
dbTable.Columns.Add("lastLogonTs", System.Type.GetType("System.Int64"));
dbTable.Columns.Add("groupGUID", System.Type.GetType("System.String"));
dbTable.Columns.Add("enabled", System.Type.GetType("System.String"));

//DataColumn [] primaryKeys = new DataColumn[2];
//primaryKeys[0] = dbTable.Columns["groupGUID"];
//primaryKeys[1] = dbTable.Columns["userGUID"];

//dbTable.PrimaryKey = primaryKeys;

private void FillDbDataTable()
Int64 countID = 0;

DateTime dateNow = DateTime.Now;

//MessageBox.Show( adTable.Rows.Count.ToString() );

WaitForAdTable( adTable.Rows.Count );
foreach( DataRow bufferRow in adTable.Rows )
DBNull dbNull = DBNull.Value;
if( bufferRow["memberOf"] != dbNull )

System.Object [] groupGUIDObject = ( System.Object [] )

//string userGUID = this.GetUserGUID(bufferRow);
string userGUID = ConvertObjectGuidToString2(bufferRow);

Int64 lastLogonTs = this.GetLogonDateTs( bufferRow );
string enabled = this.IsAccountEnabled(bufferRow);


foreach( System.Object groupDN in groupGUIDObject )
DataRow topRow = this.dbTable.NewRow();

topRow["countID"] = countID;
topRow["userGUID"] = userGUID;
topRow["lastLogonTs"] = lastLogonTs;
topRow["enabled"] = enabled;
topRow["recordDate"] = dateNow;

topRow["groupGUID"] = this.GetGroupGUID((string) groupDN );

//topRow["groupGUID"] = GetGroupGUID2( (string) groupDN );

catch ( Exception ex )


private Int64 GetLogonDateTs( DataRow bufferRow )

LargeInteger oli =(LargeInteger) bufferRow["lastLogon"]; //Set object
reference to ILargeInteger
Int64 liTicks = oli.HighPart * 0x100000000 + oli.LowPart;

return liTicks;

private string IsAccountEnabled( DataRow bufferRow )
int userAccountControl = (int) bufferRow["userAccountControl"];
int userAccountControl_Disabled = Convert.ToInt32(

string enabled = "N";

int flagExists = userAccountControl & userAccountControl_Disabled;
//if a match is found, then the disabled flag exists within the
control flags

if(flagExists >0)
enabled = "N";
enabled = "Y";

return enabled;
public string GetUserGUID( DataRow bufferRow )

string scompany = bufferRow["distinguishedName"].ToString();

string sEntry = "LDAP://"+ scompany;
DirectoryEntry entry = new DirectoryEntry( sEntry, null, null,

string nativeGUID = entry.NativeGuid;

string apiGUID = ConvertObjectGuidToString(bufferRow);
string handGUID = ConvertObjectGuidToString2(bufferRow);

MessageBox.Show( nativeGUID + "\n" + handGUID + "\n" + apiGUID);

return nativeGUID;

/// <summary>
/// Returns string array - first string in the array is customerGUID,
second customerID
/// </summary>
/// <param name="bufferRow"></param>
/// <returns></returns>

public string GetGroupGUID( string groupDN )
string groupGUID;
groupDN = groupDN.Trim();

string sEntry = "LDAP://"+ groupDN;
DirectoryEntry entry = new DirectoryEntry( sEntry, null, null,
groupGUID = entry.NativeGuid;

catch ( Exception ex )
throw new Exception(ex.Message, ex.InnerException );

return groupGUID;
// Get Guid by hand ;)
public string ConvertObjectGuidToString2(DataRow bufferRow)
Byte[] guid =(Byte[]) bufferRow["objectGUID"];

string buf = "";
string hexString;
int ubyteToInt;
for( int i = 0; i < guid.Length; i++)
ubyteToInt = ((int) guid[i]) & 0x000000FF; //ubyte to int
hexString = ubyteToInt.ToString("x"); // To hexString
while( hexString.Length < 2) hexString = "0" + hexString;
buf = buf + hexString;
return buf.ToLower();
Nov 16 '05 #1
0 4648

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

by: Skip Montanaro | last post by:
Consider the output of these two explain statements: mysql> explain select count(*) from cities,addresses,venues,events where cities.latitude <= 30.2741903768 and cities.latitude >=...
by: elcc1958 | last post by:
I need to support a VB6 application that will be receiving disconnected ADODB.Recordset from out DotNet solution. Our dotnet solution deals with System.Data.DataTable. I need to populate a...
by: Terry E Dow | last post by:
Howdy, I am having trouble with the objectCategory=group member.Count attribute. I get one of three counts, a number between 1-999, no member (does not contain member property), or 0. Using...
by: M. David Johnson | last post by:
I cannot get my OleDbDataAdapter to update my database table from my local dataset table. The Knowledge Base doesn't seem to help - see item 10 below. I have a Microsoft Access 2000 database...
by: Marcel Hug | last post by:
Hi all ! I have a table in my database, which has 3 attributes. IDFailureControl, ControlDate and ControlVersion. In the following function I test, if the date of today allready exists. Then I...
by: Yuk Tang | last post by:
I'm trying to grab the fieldnames and values from a recordset, but I'm getting errors. I have an idea what the error might come from, but I'm not sure how to correct it. I'm connecting to an...
by: sck10 | last post by:
Hello, I am using the following in ASP.NET 2.0 VB using ADODB (which is working). I would like to convert this to csharp using ADO.NET. To build the connection, I am trying to convert: ...
by: RC- | last post by:
Hi everyone, I have been searching and searching for an answer to this question using Google and what not; I have not been able to find a "clear cut" answer. OK, now the question: I have a...
by: kendrick82 | last post by:
Hi, I am developing a web application and facing a difficulty in inserting the new data in a Datatable into the MS Access databse. The below method is able to execute without any error message but...
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.