Re: ADODB to ADO.NET conversion



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/>&nbsp;&nbsp;&nbsp;&nbsp;" &
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.



.



Relevant Pages

  • Re: DirectoryService and get all groups
    ... Dim dirEnt As New DirectoryEntry ... Dim srGroupsCol As SearchResultCollection = dsGroups.FindAll ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • Re: DirectoryService and get all groups
    ... Dim dirEnt As New DirectoryEntry ... Dim srGroupsCol As SearchResultCollection = dsGroups.FindAll ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.framework.aspnet.security)
  • RE: Problem when showing MdiChild form
    ... logic order wrong in showing the MDI child form. ... Dim childFormsAs Windows.Forms.Form ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Need help to create a macro or vba script to export data from exce
    ... I think you may try to use the code below to dump the cell one by one, ... Dim fso As New FileSystemObject ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.vba)
  • RE: Need help to create a macro or vba script to export data from
    ... I think you may try to use the code below to dump the cell one by one, ... Dim fso As New FileSystemObject ... Microsoft Online Community Support ... where an initial response from the community or a Microsoft Support ...
    (microsoft.public.office.developer.vba)