Re: ADODB to ADO.NET conversion
- From: "sck10" <sck10@xxxxxxxxxxxxx>
- Date: Wed, 20 Sep 2006 17:02:17 -0500
Steven,
Thank you very much for your help.
I got it to work, but I had to add:
entry.AuthenticationType = AuthenticationTypes.None;
Is this the default? I noticed that a lot of the examples on the web
don't show this in their examples.
Thanks again, sck10
try
{
DirectoryEntry entry = new
DirectoryEntry("LDAP://ldap-uscentral.post.lucent.com:389/o=lucent.com/ou=people");
entry.AuthenticationType = AuthenticationTypes.None;
DirectorySearcher mySearcher = new DirectorySearcher(entry);
mySearcher.Filter = "(&(objectclass=person)(employeenumber=" + HRID +
"))";
SearchResultCollection mySearchResult = mySearcher.FindAll();
SearchResult result = mySearchResult[0];
DirectoryEntry item = result.GetDirectoryEntry();
foreach(PropertyValueCollection props in item.Properties)
{
Response.Write("<br />" + props.PropertyName + ": " +
props[0].ToString());
}
} // end try
"Steven Cheng[MSFT]" <stcheng@xxxxxxxxxxxxxxxxxxxx> wrote in message
news:rVJZxwG3GHA.4916@xxxxxxxxxxxxxxxxxxxxxxxx
Hello Steve,
From the code snippet you provided, you used to use the OLEDB provider to
query some LDAP directory storage and want to uprade the code into .NET
code, correct?
Based on my experience, in .net framework, the classes under the
System.DirectoryServices namespace are the prefered ones for manipulating
LDAP , ActiveDirectory service. For your scenario, if you want to query
some objects from a LDAP storage, you can use the "DirectorySearcher"
class
which can be constructed with a LDAP connectionstring and some additional
search filter or optional properties. e.g.
#the following function use DirectorySearcher to query the user objects in
the domain
==========================
Protected Sub btnQuery_Click(ByVal sender As Object, ByVal e As
System.EventArgs) Handles btnQuery.Click
Response.Write("<br/>btnQuery_Click.............")
Dim connstr =
"LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast,DC=corp,
DC=Microsoft, DC=com"
Try
Dim entry As New
DirectoryEntry("LDAP://fareast.corp.microsoft.com/OU=UserAccounts,DC=fareast
,DC=corp, DC=Microsoft, DC=com")
Dim mySearcher As New DirectorySearcher(entry)
mySearcher.Filter =
"(&(objectCategory=person)(objectClass=user)(Displayname=Steven Cheng))"
Dim mySearchResult As SearchResultCollection =
mySearcher.FindAll()
Dim result As SearchResult = mySearchResult(0)
Dim item As DirectoryEntry = result.GetDirectoryEntry()
Response.Write("<br/>Name: " & item.Name)
For Each props As PropertyValueCollection In item.Properties
Response.Write("<br/>" & props.PropertyName & ": " &
props(0).ToString())
'if you want to print out all the property values
'If (props.Count > 0) Then
' For Each obj As Object In props
' Response.Write("<br/> " &
obj.ToString())
' Next
'End If
Next
Catch ex As Exception
Response.Write("<br/>" & ex.ToString())
End Try
End Sub
===================================
here are some other good reference and examples about ADSI programming
through VB.NET:
#Quick List for Visual Basic 2005 Code Examples
http://msdn2.microsoft.com/en-us/library/ms180834.aspx
#Active Directory and VB.NET
http://www.vbdotnetheaven.com/UploadFile/johncharles/ActiveDirectoryInVB1112
2005060642AM/ActiveDirectoryInVB.aspx?ArticleID=a775db4b-3909-4d36-86e2-917b
6d693465
Sincerely,
Steven Cheng
Microsoft MSDN Online Support Lead
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.
.
- Follow-Ups:
- Re: ADODB to ADO.NET conversion
- From: Steven Cheng[MSFT]
- Re: ADODB to ADO.NET conversion
- References:
- ADODB to ADO.NET conversion
- From: sck10
- RE: ADODB to ADO.NET conversion
- From: Steven Cheng[MSFT]
- ADODB to ADO.NET conversion
- Prev by Date: Re: debugging help: How to access POST field values
- Next by Date: Re: Master has a Master?
- Previous by thread: RE: ADODB to ADO.NET conversion
- Next by thread: Re: ADODB to ADO.NET conversion
- Index(es):
Relevant Pages
|