Active directory search Help !!!

  • Thread starter Thread starter alpha
  • Start date Start date
A

alpha

Hi Friends,

I am using ADSI to fetch mail from microsoft excahnge server depanding as given in below query. But the problem is same query is returning differnt no of records like sometimes it returns 230, 250,... etc. Can anyone please tell what is amiss here. It is really driving be crazy?*&^%.

string DBConnection = "Provider=ADSDSOObject";

OleDbConnection conn = new OleDbConnection(DBConnection);

//Select query for getting the email Address, First Name and Last Name of the Users matching the search criteria

string query="SELECT mail,givenname,sn FROM 'LDAP://DC=xx,DC=Test,DC=xxx' WHERE objectClass='*' and givenname='"+ firstName +"*' and sn='"+ lastName+"*' and mail='"+emailAlias+"*' order by mail";

OleDbDataAdapter adapter = new OleDbDataAdapter();

conn.Open();

adapter.SelectCommand = new OleDbCommand(query, conn);

With Regards,
Alpha
 
¤ Hi Friends,
¤
¤ I am using ADSI to fetch mail from microsoft excahnge server depanding as given in below query. But the problem is same query is returning differnt no of records like sometimes it returns 230, 250,... etc. Can anyone please tell what is amiss here. It is really driving be crazy?*&^%.
¤
¤ string DBConnection = "Provider=ADSDSOObject";
¤
¤ OleDbConnection conn = new OleDbConnection(DBConnection);
¤
¤ //Select query for getting the email Address, First Name and Last Name of the Users matching the search criteria
¤
¤ string query="SELECT mail,givenname,sn FROM 'LDAP://DC=xx,DC=Test,DC=xxx' WHERE objectClass='*' and givenname='"+ firstName +"*' and sn='"+ lastName+"*' and mail='"+emailAlias+"*' order by mail";
¤
¤ OleDbDataAdapter adapter = new OleDbDataAdapter();
¤
¤ conn.Open();
¤
¤ adapter.SelectCommand = new OleDbCommand(query, conn);
¤

Could you explain what you mean by different? What data are you expecting and what is being
retrieved that you don't expect?


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Hello Alpha


heh...sure you want to do this through OleDB?

Check out Directory Services. Below is some sample code for accessing LDAP
using Directory Services. It's not a big step from there to access exchange
data from there



Dim Users As New TreeNode("Users")

Dim Groups As New TreeNode("Groups")

Dim Services As New TreeNode("Services")

Dim Other As New TreeNode("Other")

Me.TreeView1.Nodes.AddRange(New TreeNode() {Users, Groups, Services, Other})

Dim entry As New DirectoryServices.DirectoryEntry(LDAP://yourservernamehere)

Dim mySearcher As New System.DirectoryServices.DirectorySearcher(entry)

mySearcher.Sort.Direction = SortDirection.Ascending

Dim result As System.DirectoryServices.SearchResult

For Each result In mySearcher.FindAll

Dim NewNode As New TreeNode(result.GetDirectoryEntry.Name & ":" &
result.GetDirectoryEntry.SchemaClassName)

Select Case result.GetDirectoryEntry.SchemaClassName.ToUpper

Case Is = "USER"

Users.Nodes.Add(NewNode)

Case Is = "GROUP"

Groups.Nodes.Add(NewNode)

Case Is = "SERVICE"

Services.Nodes.Add(NewNode)

Case Else

Other.Nodes.Add(NewNode)

End Select

Next



--
Ibrahim Malluf
http://www.malluf.com
==============================================
MCS Data Services Code Generator
http://64.78.34.175/mcsnet/DSCG/Announcement.aspx
==============================================
Pocket PC Return On Investment Calculator
Free Download http://64.78.34.175/mcsnet/kwickKalk1.aspx



alpha said:
Hi Friends,

I am using ADSI to fetch mail from microsoft excahnge server
depanding as given in below query. But the problem is same query is
returning differnt no of records like sometimes it returns 230, 250,... etc.
Can anyone please tell what is amiss here. It is really driving be
crazy?*&^%.
string DBConnection = "Provider=ADSDSOObject";

OleDbConnection conn = new OleDbConnection(DBConnection);

//Select query for getting the email Address, First Name and Last Name of
the Users matching the search criteria
string query="SELECT mail,givenname,sn FROM 'LDAP://DC=xx,DC=Test,DC=xxx'
WHERE objectClass='*' and givenname='"+ firstName +"*' and sn='"+
lastName+"*' and mail='"+emailAlias+"*' order by mail";
OleDbDataAdapter adapter = new OleDbDataAdapter();

conn.Open();

adapter.SelectCommand = new OleDbCommand(query, conn);

With Regards,
Alpha
Community Website: http://www.dotnetjunkies.com/newsgroups/
 
Thanks for the solution...but still I am not trying to understand that for same query why we are getting different no of records...... any pointer for this will be of great help.

Anyway thanks for the solution.

With ragards,
Alpha
 
¤
¤ Thanks for the solution...but still I am not trying to understand that for same query why we are getting different no of records...... any pointer for this will be of great help.
¤
¤ Anyway thanks for the solution.
¤

I don't know how you are determining how many rows are being returned, but you may want to look at
the paging issue:

HOWTO: Work Around the Limitation that ADO MaxRecord Is Not Implemented in DS OLEDB Provider
ADsDSOObject
http://support.microsoft.com/default.aspx?scid=kb;en-us;269361


Paul ~~~ (e-mail address removed)
Microsoft MVP (Visual Basic)
 
Back
Top