Active directory select and display with asp.net (oledb) (error code: DB_E_ERRORSINCOMMAND(0x80040E1

Posted by Phil on Stack Overflow See other posts from Stack Overflow or by Phil
Published on 2010-04-01T06:59:44Z Indexed on 2010/04/01 7:03 UTC
Read the original article Hit count: 704

I am trying to make a page which displays some user information returned from active directory. Here is my code so far:

 Dim oConnection As OleDbConnection
    Dim oCmd As OleDbCommand
    Dim strADOQuery As String
    Dim oleReader As OleDbDataReader
    oConnection = New OleDbConnection()
    oCmd = New OleDbCommand()
    oConnection.ConnectionString = "Provider=ADsDSOObject;"

    oConnection.Open()
    oCmd.Connection = oConnection


    strADOQuery = "select distinguishedName, cn, givenname, sn, mail, middleName, displayName, description, telephonenumber, physicalDeliveryOfficeName, employeeID from 'LDAP://dc=foo,dc=ac,dc=uk' WHERE objectCategory='Person' AND objectClass='user' AND sAMAccountName='" & Uname & "'"""
    oCmd.CommandText = strADOQuery
    oCmd.CommandTimeout = 600
    oCmd.ExecuteReader()
    While oleReader.Read
        ADDN = r("distinguishedName")
        ADCommonName = r("cn")
        ADFirstName = r("givenname")
        ADLastName = r("sn")
        ADEmail = r("mail")
        ADFirstandLast = r("displayName")
        ADDescription = r("description")
        ADTelephone = r("telephonenumber")
        ADOffice = r("physicalDeliveryOfficeName")
        ADStaffnum = r("employeeID")
    End While
    oConnection.Close()
    oleReader.Close()

I'm finding it hard to see exactly what is wrong with the code. The error message presented is vague:

'ADsDSOObject' failed with no error message available, result code: DB_E_ERRORSINCOMMAND(0x80040E14).

Any assistance would be greatly appreciated

Thanks.

© Stack Overflow or respective owner

Related posts about active-directory

Related posts about ASP.NET