0

LDAP サーバーに接続して連絡先を読み取り、テーブルに保存しようとしています。

一部のサーバーではコードが機能しますが、他の多くのサーバーでは機能しません。このエラーが発生しました:保護されたメモリエラーの読み取りまたは書き込みを試みました

何が問題なのかわからない。

これが私のコードです。あなたが私を助けてくれることを願っています:

Protected Sub ADLoader()
    'Holt die Verbindungdaten aus dem web.config
    config = DirectCast(ConfigurationManager.GetSection("ldapSettings"), NameValueCollection)
    Dim server, username, password, attrsAMAccountName, basisDN, filterAttr, attrNachname, attrVorname, attrEmail, attrTel, attrAbteilung, attrPlz, attrStadt, attrStrasse, attrTrigram, attrName As String
    Dim i As Integer = 0
    server = config.[Get]("server")
    username = config.[Get]("username")
    password = config.[Get]("password")
    basisDN = config.[Get]("basisDN")
    filterAttr = config.[Get]("filterAttr")
    attrNachname = config.[Get]("attrNachname")
    attrVorname = config.[Get]("attrVorname")
    attrEmail = config.[Get]("attrEmail")
    attrTel = config.[Get]("attrTel")
    attrAbteilung = config.[Get]("attrAbteilung")
    attrPlz = config.[Get]("attrPlz")
    attrStadt = config.[Get]("attrStadt")
    attrStrasse = config.[Get]("attrStrasse")
    attrTrigram = config.[Get]("attrTrigram")
    attrName = config.[Get]("attrName")
    attrsAMAccountName = config.[Get]("attrsAMAccountName")
    If CustomUser = "FIFA" Then
        attrsAMAccountName = config.[Get]("attrTrigram")
    End If
    Dim pfad As String = "LDAP://" + server + "/" + basisDN
    Dim filter As String = " (&(objectCategory=user)(" + filterAttr + "=*))"
    Dim results As SearchResultCollection = Nothing

    'Baut die Verbindung zum Active Directory auf und speichert die Daten in eine Liste
    Try
        Dim entry As New DirectoryEntry
        entry.Path = pfad
        entry.Username = username
        entry.Password = password
        entry.AuthenticationType = AuthenticationTypes.None

        Dim mySearcher As New DirectorySearcher(entry)
        mySearcher.PropertiesToLoad.Add(attrNachname)
        mySearcher.PropertiesToLoad.Add(attrVorname)
        mySearcher.PropertiesToLoad.Add(attrEmail)
        mySearcher.PropertiesToLoad.Add(attrTel)
        mySearcher.PropertiesToLoad.Add(attrAbteilung)
        mySearcher.PropertiesToLoad.Add(attrPlz)
        mySearcher.PropertiesToLoad.Add(attrStadt)
        mySearcher.PropertiesToLoad.Add(attrName)
        mySearcher.PropertiesToLoad.Add(attrsAMAccountName)
        'mySearcher.PropertiesToLoad.Add(zusatzFeld)
        mySearcher.Filter = filter     ' Sucht nur in der Kategorie user und nur mit trigram
        mySearcher.Sort.PropertyName = attrNachname
        mySearcher.PageSize = 100
        Dim result As SearchResultCollection
        result = mySearcher.FindAll()     <<<<<<<<<<< HERE IS THE ERROR >>>>>>>
        log.Debug("AD Importer: Gefundene Personen im Active Directory = " + result.Count.ToString)
        Dim searchResult As SearchResult

        For Each searchResult In result
            Dim propcoll As ResultPropertyCollection = searchResult.Properties
            Dim ssoBenutzer As New BiObPerson
            For Each key As String In propcoll.PropertyNames
                If key = attrsAMAccountName Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.BenutzerName = values.ToString()
                        ssoBenutzer.UniqueName = ssoBenutzer.BenutzerName
                    Next
                End If
                If key = attrAbteilung Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Abteilung = values.ToString()
                    Next
                End If
                If key = attrNachname Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Nn = values.ToString()
                    Next
                End If
                If key = attrVorname Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Vn = values.ToString()
                    Next
                End If
                If key = attrEmail Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Email = values.ToString()
                    Next
                End If
                If key = attrTel Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Tel = values.ToString()
                    Next
                End If
                If key = attrStrasse Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.Streetaddress = values.ToString()
                    Next
                End If
                If key = attrStadt Then
                    For Each values As Object In propcoll(key)
                        ssoBenutzer.StadtName = values.ToString()
                    Next
                End If

            Next
            i = 1 + i
            log.Debug("AD Importer: Folgende Person wird in die Datenbank hinzugefügt = " + ssoBenutzer.BenutzerName)
            CreateOrUpdateSSOUser(ssoBenutzer, username)

        Next
        Label1.Text = "(" & i & ")" & " Fertig. "
    Catch ex As Exception
        Debug.WriteLine("AD Importer: Fehlgeschlagen=" + ex.Message)
        log.Debug("AD Importer: Fehler bei der Verbindung zum AD Server" + ex.Message)

    End Try

End Sub
4

2 に答える 2

0

私は私のエラーを見つけました。

web.config でプロパティ「attrName」を指定するのを忘れました。プロパティが見つからず、エラー メッセージが表示されました。

今では動作します。

于 2013-06-26T08:37:33.050 に答える