Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Unable to get certain usernames from AD

Reply
Thread Tools

Unable to get certain usernames from AD

 
 
furiousmojo@gmail.com
Guest
Posts: n/a
 
      06-30-2006
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(connectionStri ng)

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


----------------------------------------------------------------------

 
Reply With Quote
 
 
 
 
furiousmojo@gmail.com
Guest
Posts: n/a
 
      07-07-2006
Joe K. solved my problem! The answer was using searcher.pagesize. By
default, the query is limited to 1000 results to prevent DOS attacks.

http://www.velocityreviews.com/forums/(E-Mail Removed) wrote:
> 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(connectionStri ng)
>
> 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
>
>
> ----------------------------------------------------------------------


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Windows Vista cannot obtain an IP address from certain routers or from certain non-Microsoft DHCP Brian W Wireless Networking 7 01-31-2010 03:46 AM
Binding certain rows to certain columns in GridView? bernard.oflynn@gmail.com ASP .Net 2 03-25-2008 03:49 PM
Finding one certain line in a file is easy but how to look forheadlines and something just under this certain headline? kazaam Ruby 3 08-26-2007 03:34 PM
Expanding certain path to certain node in a JTree arun.hallan@gmail.com Java 0 01-08-2005 08:26 PM
field validation as float with certain integer and certain decimal SAN CAZIANO Javascript 8 10-15-2004 05:24 PM



Advertisments