473,473 Members | 1,819 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Unable to get certain usernames from AD

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
----------------------------------------------------------------------

Jun 30 '06 #1
1 1309
Joe K. solved my problem! The answer was using searcher.pagesize. By
default, the query is limited to 1000 results to prevent DOS attacks.

fu*********@gmail.com 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
----------------------------------------------------------------------
Jul 7 '06 #2

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

Similar topics

1
by: Eric McIntyre | last post by:
I am using DB2 UDB 8.1. Can I add users to the database that have dots in their usernames (firstname.lastname)? Thanks Eric
2
by: NG WEI CHUNG | last post by:
Hi, Some of my clients site is unable to view the ASP .NET page due to the proxy server and firewall or perhaps IE setting etc, I m not sure what is the actual cause of the problem, it display...
1
by: Joe | last post by:
Hi, A part of our ASP website is password protected. People need to create accounts in order to gain access to the secured website. The username is email. After the user logs in a session cookie...
3
by: Microsoft | last post by:
Hello all I am new to 2003 server and Active Directory, I want to put spaces in the usernames for the domain users. Now my question is will that create any problems in the future with anything...
6
by: Brad | last post by:
I have a win2003 server workstation with multiple webs, each web has it's own ip address. In VS2005, if I select to open an existing web site, select Local IIS, the dialog correctly displays a...
1
by: Henry Stockbridge | last post by:
Hi, I am attempting to incorporate Dev Ashish's fOSUserName code with multiple UserNames but come up with a runtime error (13) / Type mismatch. Any help you can lend would be appreciated. Here...
0
by: npaulus | last post by:
Hi, I am trying to list all usernames from active directory under the domain 'tefter.com' DirectoryEntry entry = new DirectoryEntry(); DirectorySearcher mySearcher = new...
12
by: mvsguy | last post by:
I'm an Access noob and apologize if I'm asking a stupid question. The problem is that I'm unable to design/preview reports on a database. How do I go about fixing this? Background - A user has...
1
by: Markw | last post by:
Hi folks I think I've got a variable problem but not 100% sure. Background: I took the CMS example from chapter 6 in "Build your Own Database Driven Website Using PHP&MySQL" and have attempted to...
0
marktang
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,...
0
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...
0
Oralloy
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,...
0
jinu1996
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...
1
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.