Unable to get certain usernames from AD

F

furiousmojo

The problem: Most usernames show up in the dropdownlist, but a random
few do not show up. Why? If I put the filter below into my Users and
Computers snap-in as an advanced search, it finds all of them.

Here's the meat of the ldap search:

Private Function GetUsernames() As DataTable

Dim rootEntry As New DirectoryEntry("LDAP://" &
ConfigurationManager.AppSettings("FQDN"))
Dim searcher As New DirectorySearcher(rootEntry)
searcher.SearchScope = SearchScope.Subtree

searcher.Filter =
"(&(ObjectClass=user)(ObjectCategory=person))"
searcher.PropertiesToLoad.Add("samAccountName")

Dim srcResults As SearchResultCollection = searcher.FindAll()

Dim srResult As SearchResult
Dim rpcPropertyCollection As ResultPropertyCollection
Dim objMember As Object

Dim myDataTable As New DataTable("dtUsers")

Dim dcUserName As New DataColumn("UserName", GetType(String))

myDataTable.Columns.Add(dcUserName)

For Each srResult In srcResults
Dim dr As DataRow
dr = myDataTable.NewRow()
dr("UserName") =
CType(srResult.Properties("samAccountName")(0), String)
myDataTable.Rows.Add(dr)
Next

myDataTable.DefaultView.Sort = "UserName"

Return myDataTable
End Function

This is the binding of the datalist containing the column with
dropdownlists of usernames.

Private Sub BindSearchResultsDataList()

Dim myDataListItem As DataListItem
Dim strFirstName, strLastName As String

strFirstName = txtFirstName.Text
strLastName = txtLastName.Text

strFirstName = Replace(strFirstName, "'", "''")
strLastName = Replace(strLastName, "'", "''")

Dim connectionString As String = DecryptConnectionString()
Dim dbConnection As System.Data.IDbConnection = New
System.Data.SqlClient.SqlConnection(connectionString)

Dim queryString As String = "BLANKED OUT SELECT QUERY"
Dim dbCommand As System.Data.IDbCommand = New
System.Data.SqlClient.SqlCommand
dbCommand.CommandText = queryString
dbCommand.Connection = dbConnection

dbConnection.Open()

Dim myReader As SqlDataReader
myReader = dbCommand.ExecuteReader()

dlSearchResults.DataSource = myReader
dlSearchResults.DataBind()

If dlSearchResults.Items.Count <> "0" Then
dlSearchResults.Visible = True
Else
dlSearchResults.Visible = False
lblSearchResult.Text = "No employees found."
End If

dbConnection.Close()

Dim dtUsernames As DataTable = GetUsernames()

For Each myDataListItem In dlSearchResults.Items
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataSource = dtUsernames
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataTextField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataValueField = "Username"
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).DataBind()
CType(myDataListItem.FindControl("ddlUsername"),
DropDownList).Items.Insert(0, "")
Next
End Sub


----------------------------------------------------------------------
 
F

furiousmojo

Joe K. solved my problem! The answer was using searcher.pagesize. By
default, the query is limited to 1000 results to prevent DOS attacks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,969
Messages
2,570,161
Members
46,705
Latest member
Stefkari24

Latest Threads

Top