RE: ADODB to ADO.NET conversion



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: MS VC++ 2003 and ADSI IID_IDirectorySearch
    ... Now i would only need to know which LDAP (i noticed that ... IDirectorySearch doesn't support "WinNT:") query to use to ...
    (microsoft.public.win2000.active_directory)
  • Re: MS VC++ 2003 and ADSI IID_IDirectorySearch
    ... Now i would only need to know which LDAP (i noticed that ... IDirectorySearch doesn't support "WinNT:") query to use to ...
    (microsoft.public.win32.programmer.networks)
  • Re: DropDownList has SelectedValue which in invalid
    ... resulting in the invalid SelectedValue error. ... Dim ddl1 As DropDownList = CType, ... From your description you want to avoid getting the exception: ... Microsoft Online Support ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: DataGridView Formatting and Filtering
    ... Private Sub Form1_Load(ByVal sender As System.Object, ... Dim i As Integer ... by register the KeyDown event of TextBox in the DataGridViewTextBoxColumn ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)
  • RE: Converting VB6 Fileopen/input/close to vb.net
    ... Dim file_num As Integer = FreeFile ... Microsoft MSDN Online Support Lead ... Converting VB6 Fileopen/input/close to vb.net ... Dim ClientFileName As String ...
    (microsoft.public.dotnet.languages.vb)

Loading