none
Active Directory bulk data update error System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) The server is not operational

    Question

  • Hello, 

    we are trying to update bulk data into Active Directory from some database table. If we run for say 40000 users, it fails in between While updating its failing with an exception that. The server is not operational.

    at System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail)
       at System.DirectoryServices.DirectoryEntry.Bind()
       at System.DirectoryServices.DirectoryEntry.get_AdsObject()
       at System.DirectoryServices.DirectorySearcher.FindAll(Boolean findMoreThanOne)
       at System.DirectoryServices.DirectorySearcher.FindOne()

    Below is the piece of code updating the records ...

    Public Function UpdateAdam(ByVal iRunId As Integer, ByVal strTimestamp As String) As Boolean
            Dim dtAdamUpdates As DataTable = Nothing
            Dim iloopCount As Integer = 0
            Dim oDataAccess As New DataAccess
            Dim strMailID As String = String.Empty
            Dim strEMailID As String = String.Empty
            Dim strAttributeName As String = String.Empty
            Dim strAttributeValue As String = String.Empty
            'Dim dirResult As DirectoryEntry = Nothing
            Dim dsDirSearcher As DirectorySearcher = Nothing
            Dim results As SearchResult = Nothing
            Dim strADAMUserName As String = String.Empty
            Dim strADAMPassword As String = String.Empty
            Dim strEmailIDEx As String = String.Empty
            Dim oledbcomCommand As OleDbCommand = Nothing
            Dim oConnection As OleDbConnection = Nothing
            Dim dirEntry As DirectoryEntry = Nothing
            Dim strdate As String
            Dim drDataReader As OleDbDataReader = Nothing
            Dim iCount As Integer = 0
            Dim iRecordCount As Integer = 0

            Dim strLDAPServer As String = String.Empty
            Dim strADAMDirPath As String = String.Empty

            Try
                strLDAPServer = Common.GetValueFromConfig(Constant.LDAP_SERVER)
                strADAMDirPath = Common.GetValueFromConfig(Constant.ADAM_DIR_PATH)

                If String.IsNullOrEmpty(StrConnectionString) Then
                    SetConnectionString()
                End If
                strADAMUserName = Common.GetValueFromConfig(Constant.ADAM_WRITE_USER_NAME)
                '' set password
                strADAMPassword = Common.Decrypt(Common.GetValueFromConfig("ADAMWritePassword"))
                strdate = Now.ToString("dd/MM/yyyy HH:mm:ss")
                Logger.InsertIntoProcessLog(iRunId, collStatus("21").ToString().Replace("##Date##", strdate))

                oDataAccess.UpdateProcessDetails(iRunId, String.Empty, String.Empty, Constant.STATUS_DETAILS_ADAM_UPDATE + " " + strdate, String.Empty, String.Empty, String.Empty)

                'Create a oledbCommand for the given query.
                dirEntry = Adam.GetDirectoryEntry(strADAMUserName, strADAMPassword)
                dsDirSearcher = New DirectorySearcher(dirEntry)
                oConnection = New OleDbConnection(StrConnectionString)
                oConnection.Open()
                oledbcomCommand = New OleDbCommand("PKG_ADAM_EXTRACT.SP_GetADAMUpdates", oConnection)
                oledbcomCommand.CommandType = CommandType.StoredProcedure
                oledbcomCommand.Parameters.Add("inRUNID", OleDbType.Integer).Value = iRunId
                drDataReader = oledbcomCommand.ExecuteReader()
                If Not drDataReader Is Nothing Then
                    If drDataReader.HasRows Then
                        While drDataReader.Read()
                            strMailID = drDataReader.Item(("EMAILID")).ToString()
                            strAttributeName = drDataReader.Item("ATTRIBUTENAME").ToString().Trim()
                            strAttributeValue = drDataReader.Item("ATTRIBUTEVALUE").ToString().Trim()
                            If Not String.IsNullOrEmpty(strMailID) Then
                                If Not strEMailID.ToUpper.Equals(strMailID.ToUpper) Then
                                    If Not String.IsNullOrEmpty(strEMailID) Then
                                        Try
                                            dirEntry.CommitChanges()
                                        Catch exCom As DirectoryServicesCOMException
                                            Logger.WriteLog("Console Adam1 DirectoryServicesCOMException : Update Failed for EmailID = " + strEMailID)
                                            Logger.WriteLog("DirectoryServicesCOMException = " + exCom.ToString)
                                            Logger.WriteLog("DirectoryServicesCOMException Message = " + exCom.Message)
                                            Logger.WriteLog("DirectoryServicesCOMException Error code = " + exCom.ExtendedError.ToString())
                                            Logger.WriteLog("DirectoryServicesCOMException ExtendedErrorMessage = " + exCom.ExtendedErrorMessage)
                                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                                strEmailIDEx = strEMailID
                                            Else
                                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                                            End If
                                        Catch excomex As COMException
                                            Logger.WriteLog("Console Adam1 COMException - UpdateAdam COMException Exception : " + excomex.Message + excomex.StackTrace)
                                            Logger.WriteLog("Console Adam1 COMException: COMException Exception= " + excomex.ErrorCode.ToString())
                                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                                strEmailIDEx = strEMailID
                                            Else
                                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                                            End If
                                        Catch exc As Exception
                                            Logger.WriteLog("Console Adam1 : Update Failed for EmailID = " + strEMailID)
                                            Logger.WriteLog("Exception = " + exc.Message)
                                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                                strEmailIDEx = strEMailID
                                            Else
                                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                                            End If
                                        End Try
                                    End If
                                    strEMailID = strMailID
                                    dirEntry.Path = strLDAPServer & strADAMDirPath
                                    dsDirSearcher.Filter = "(&(objectCategory=Person)(Mail=" & strEMailID & "))"
                                    dsDirSearcher.SearchScope = DirectoryServices.SearchScope.Subtree
                                    results = dsDirSearcher.FindOne()
                                    dirEntry.Path = results.Path
                                    iRecordCount = iRecordCount + 1
                                End If
                                If results IsNot Nothing Then
                                    If Not String.IsNullOrEmpty(strAttributeValue) Then
                                        dirEntry.Properties(strAttributeName).Value = strAttributeValue
                                    End If
                                End If
                            End If
                        End While
                        If Not oConnection Is Nothing Then
                            oConnection.Close()
                        End If
                        Try
                            dirEntry.CommitChanges()
                        Catch exCom As DirectoryServicesCOMException
                            Logger.WriteLog("Console Adam2 DirectoryServicesCOMException : Update Failed for EmailID = " + strEMailID)
                            Logger.WriteLog("DirectoryServicesCOMException = " + exCom.ToString)
                            Logger.WriteLog("DirectoryServicesCOMException Message = " + exCom.Message)
                            Logger.WriteLog("DirectoryServicesCOMException Error code = " + exCom.ExtendedError.ToString())
                            Logger.WriteLog("DirectoryServicesCOMException ExtendedErrorMessage = " + exCom.ExtendedErrorMessage)
                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                strEmailIDEx = strEMailID
                            Else
                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                            End If
                        Catch excomex As COMException
                            Logger.WriteLog("Console Adam2 COMException - UpdateAdam COMException Exception : " + excomex.Message + excomex.StackTrace)
                            Logger.WriteLog("Console Adam2 COMException: COMException Exception= " + excomex.ErrorCode.ToString())
                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                strEmailIDEx = strEMailID
                            Else
                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                            End If
                        Catch exc As Exception
                            Logger.WriteLog("Console Adam2 : Update Failed for EmailID = " + strEMailID)
                            Logger.WriteLog("Exception = " + exc.Message)
                            If String.IsNullOrEmpty(strEmailIDEx) Then
                                strEmailIDEx = strEMailID
                            Else
                                strEmailIDEx = strEmailIDEx + "," + strEMailID
                            End If
                        End Try
                    End If
                End If
                dsDirSearcher.Dispose()
                dirEntry.Dispose()
                dirEntry.Close()
                Logger.WriteLog("Console Adam : Update Completed")

                ''update time stamp T_ROSETTA_ADAM_UPDATES
                oDataAccess.UpdateADAMTimeStamp(iRunId, strEmailIDEx)
                Logger.WriteLog("Console Adam : UpdateADAMTimeStamp - End ")
                Logger.WriteLog("Console Adam : No of record processed = " + iRecordCount.ToString())
                oDataAccess.UpdateDeltaAttributes(strTimestamp)
                Logger.WriteLog("Console Adam : UpdateDeltaAttributes - End ")
                strdate = Now.ToString("dd/MM/yyyy HH:mm:ss")
                Logger.InsertIntoProcessLog(iRunId, collStatus("22").ToString().Replace("##Date##", strdate).Replace("##Status##", Constant.PROCESS_COMPLETE))
                Logger.WriteLog("Console Adam : UpdateAdam - End ")
                Return True
            Catch exCom As DirectoryServicesCOMException
                Logger.WriteLog("Console Adam3 DirectoryServicesCOMException UpdateAdam - Exception  for strEMailID " + strEMailID + "No of record processed = " + iRecordCount.ToString())
                Logger.WriteLog("DirectoryServicesCOM Exception = " + exCom.ToString)
                Logger.WriteLog("DirectoryServicesCOMException Message = " + exCom.Message)
                Logger.WriteLog("DirectoryServicesCOMException Error code = " + exCom.ExtendedError.ToString())
                Logger.WriteLog("DirectoryServicesCOMException ExtendedErrorMessage = " + exCom.ExtendedErrorMessage)
                oDataAccess.UpdateProcessDetails(iRunId, String.Empty, Constant.PROCESS_FAILED, String.Empty, Constant.PROCESS_FAILED, String.Empty, String.Empty)
                strdate = Now.ToString("dd/MM/yyyy HH:mm:ss")
                Logger.InsertIntoProcessLog(iRunId, collStatus("22").ToString().Replace("##Date##", strdate).Replace("##Status##", Constant.PROCESS_FAILED))
                Return False
                Throw
            Catch excomex As COMException
                Logger.WriteLog("Console Adam3 COMException UpdateAdam - Exception  for strEMailID " + strEMailID + "No of record processed = " + iRecordCount.ToString())
                Logger.WriteLog("Console Adam3 COMException - UpdateAdam COMException Exception : " + excomex.Message + excomex.StackTrace)
                Logger.WriteLog("Console Adam3 COMException: COMException Exception= " + excomex.ErrorCode.ToString())
                oDataAccess.UpdateProcessDetails(iRunId, String.Empty, Constant.PROCESS_FAILED, String.Empty, Constant.PROCESS_FAILED, String.Empty, String.Empty)
                strdate = Now.ToString("dd/MM/yyyy HH:mm:ss")
                Logger.InsertIntoProcessLog(iRunId, collStatus("22").ToString().Replace("##Date##", strdate).Replace("##Status##", Constant.PROCESS_FAILED))
                Return False
                Throw
            Catch ex As Exception
                Logger.WriteLog("Console Adam3 : UpdateAdam - Exception  for strEMailID " + strEMailID + "No of record processed = " + iRecordCount.ToString())
                Logger.WriteLog("Console Adam3 - UpdateAdam Exception : " + ex.Message + ex.StackTrace)
                oDataAccess.UpdateProcessDetails(iRunId, String.Empty, Constant.PROCESS_FAILED, String.Empty, Constant.PROCESS_FAILED, String.Empty, String.Empty)
                strdate = Now.ToString("dd/MM/yyyy HH:mm:ss")
                Logger.InsertIntoProcessLog(iRunId, collStatus("22").ToString().Replace("##Date##", strdate).Replace("##Status##", Constant.PROCESS_FAILED))
                Return False
                Throw
            Finally
                If Not oledbcomCommand Is Nothing Then
                    Try
                        oledbcomCommand = Nothing
                    Catch ex As Exception
                        'Logger.WriteLog("Console Adam : UpdateAdam: oledbcomCommand.Dispose(): Exception")
                        '' leave as an know issue.
                    End Try
                End If
                If Not oConnection Is Nothing Then
                    Try
                        oConnection.Close()
                    Catch ex As Exception
                        '' leave as an know issue.
                    End Try
                End If
                If Not dirEntry Is Nothing Then
                    Try
                        dirEntry.Close()
                        dirEntry.Dispose()
                    Catch ex As Exception

                    End Try

                End If
                'If Not dirResult Is Nothing Then
                '    dirResult.Close()
                'End If
                Try
                    drDataReader.Close()
                Catch ex As Exception

                End Try
            End Try

        End Function

     

    After taking traces on Active directory server it found that dirEntry.Path actually unbinds/binds/open new connection to ADAM AD. Can sombody help in this,...is there any better way to implement bulk data update to ADAM AD.

     

    Thanks, P

    Thursday, November 11, 2010 11:22 AM

All replies

  • Hi Pankaj,
     In your code try adding a line to refresh the Active directory cache, while taking values of the attributes.

    Here's the code

    ' Add this to refresh the cache
    dirEntry.RefreshCache(New String(){strAttributeName})
    dirEntry.Properties(strAttributeName).Value = strAttributeValue
    

     


    If a post answers your question, please click Mark As Answer on that post and Mark as Helpful. Happy Coding...
    Saturday, December 31, 2011 5:53 AM