Designer - SQL Database Import not Updating UNSAccountB

Gurus,

I eluded to this question in a previous post and despite my best efforts, I can't find a solution yet. So here is the situation, one of the applications we are attesting to runs off an MS SQL Database and our DBAs have basically given the Quest account rights to run a few stored processes so that it can synch the users/groups from the SQL application to Quest. The script basically opens a connection string to the database, runs the stored procs and uses the data to populate users (one script) and populate data base roles (other script) into UNSAccountB and UNSGroupB respectively while tagging XProxyContext to be the application name... lets call it DBApp1 for privacy.

In the Production environment, the sccripts work just fine... they pull the data in and populate accordingly. I used the Database Transport tool to import all Change Labels into the Test lab. After verifying that AD synch was working Dev and then making sure that Manager > Unified Namespace has an entry for DBApp1, I ran the import. I watched the job logs intently - refreshing every few seconds, just to make sure everything worked. Yay! The script completed and I got NO errors. I even have the script writing a log file to show me what it does. The log file shows several new inserts into the database. Yay!

THEN... I checked UNSAccountB and UNSGroupB. NOTHING is there... There are no records at all...

I tried the same process again with DBApp2. Again, all things look great! Imports run and NOTHING in UNSAccountB or UNSGroupB. What the heck happened? Where did this stuff go? If the logs think everything is fine and the database is sending data (I verified this). Why doesn't it populate into Quest? Can anyone provide me some insight?

Thanks in advance!

Parents
  • Alright Steffen. Here is the first script - the user import script. I have sanitized portions of it to protect the innocent but the entire contents are there.

    #If Not SCRIPTDEBUGGER Then

    References VI.DataImport.dll

    Imports System.Collections.Generic

    Imports System.IO

    Imports System.Globalization

    Imports VI.DB.Specialized

    Imports VI.DataImport

    #End If

    Public Sub TST_DBApp2_Import(ByVal dfImport As DataFileImport)

        ' Standard variables

        Dim logSection As IDisposable

        Dim milliSec As Double = Timer

              Dim logFile As String =Connection.GetConfigParm("Custom\LogFileOutputDirectory") & "\TST_DBApp2_Import_" & Year(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now) & milliSec.ToString & ".log"

        Dim f As ISqlFormatter = Connection.SqlFormatter

              ' Table

        Dim table As TableDef = Connection.Tables("UNSAccountB")

              ' Do not delete any objects, if this marker is set

              Dim doNotDelete As Boolean = False

              ' Line counter

        Dim counter As New LineCounter()

              Dim obj As ISingleDbObject = Nothing

              ' Value provider

              Dim lineData As New LineValueProvider(New String() {"User ID", "User Name", "User Last Updated By", "User Last Updated On", "", "", ""})

              Provider = lineData

              ' Import from an external database

              Dim lineProvider As New DbLineProvider()

              lineProvider.ProviderName = "System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

              lineProvider.ConnectionString = Connection.GetConfigParm("Custom\DBApp2\ConnectionString")

              ' SQL statement

              Dim statement As New PlainSqlStatement()

              statement.Statement = "SELECT U.UserId AS [User ID], U.UserName AS [User Name], U.LastUpdateID AS [User Last Updated By], U.LastUpdated AS [User Last Updated On] FROM TST..ssMasUser U"

     

              lineProvider.Statement = statement

     

              '

        ' Configure column resolution

              '

     

        ' Column indices

        Const iAccountName As Integer = 0

        Const icn As Integer = 1

              ' Resolver to get column data from import data

        Dim columnAccountName As IResolveImportValue = New ResolveImportValueSimple("AccountName")

        Dim columncn As IResolveImportValue = New ResolveImportValueSimple("cn")

              ' Build a dictionary: The last parameter forces exceptions when duplicate keys are found

        Dim columnUID_Person As New ResolveImportValueHashed( _

            Connection, _

            ObjectWalker.ColDefs(table, "FK(UID_Person).CentralAccount"), False)

              ' Build a dictionary: The last parameter forces exceptions when duplicate keys are found

        Dim columnUID_UNSContainerB As New ResolveImportValueHashed( _

            Connection, _

            ObjectWalker.ColDefs(table, "FK(UID_UNSContainerB).canonicalname"), False)

        Dim columnXProxyContext As IResolveImportValue = New ResolveImportValueSimple("XProxyContext")

              ' Set connection variables

              Connection.Variables("FULLSYNC") = "true"

        Try

            '

            ' Create a dictionary for the destination table

            '

            Dim colImport As IColDbObject = Connection.CreateCol("UNSAccountB")

            Dim elemsByKey As New Dictionary(Of String, IColElem)(StringComparer.OrdinalIgnoreCase)

                        logSection = dfImport.LogSection(#LD("Bilde Index über bestehende Daten")#)

                        Try

                                  ' Set keys and values as display items to load them with the collection

                                  colImport.Prototype("AccountName").IsDisplayItem = True

                                  colImport.Prototype("cn").IsDisplayItem = True

                                  colImport.Prototype("UID_Person").IsDisplayItem = True

                                  colImport.Prototype("UID_UNSContainerB").IsDisplayItem = True

                                  colImport.Prototype("XProxyContext").IsDisplayItem = True

                                  colImport.Prototype.WhereClause = "xproxycontext = N'DBApp2'"

     

                                  ' Load the collection

                                  colImport.Load(CollectionLoadType.Slim)

                                  ' Put the entries in the dictionary

                                  For Each elem As IColElem In colImport

                                            Dim key As String

                                            key = elem.GetValue("AccountName").ToString

                                            'VID_Write2Log(logFile,String.Format("Processing key: {0}",key))

                                            If elemsByKey.ContainsKey(key) Then

                                                      VID_Write2Log(logFile,String.Format("Duplicate key: {0}",key))

                                                      dfImport.Log(MsgSeverity.Serious, #LD("Duplicate key: {0}", key)#)

                                            Else

                                                      'VID_Write2Log(logFile,String.Format("Adding key {0} to elemsByKey",key))

                                                      elemsByKey.Add(key, elem)

                                            End If

                                  Next

            Finally

                If Not logSection Is Nothing Then

                                            logSection.Dispose()

                                            logSection = Nothing

                                  End If

            End Try

     

                        'VID_Write2Log(logFile,String.Format("---------------Finished processing {0} keys",elemsByKey.Count))

                        logSection = dfImport.LogSection(#LD("Import data from file")#)

            Try

                                  For Each line As Line In lineProvider.GetLines(counter)

                                            ' Pay attention to the Stop flag

                                            If StopProcessing Then

                                                      dfImport.Log(MsgSeverity.Warning, #LD("Abarbeitung wurde gestoppt.")#)

                                                      Exit For

                                            End If

     

                                            Try

                                                      ' Get raw data from the current line

                                                      Dim key As String

                                                      Dim valAccountName As String

                                                      Dim resAccountName As String

                                                      Dim valcn As String

                                                      Dim rescn As String

                                                      Dim valUID_Person As String

                                                      Dim resUID_Person As String

                                                      Dim valUID_UNSContainerB As String

                                                      Dim resUID_UNSContainerB As String

                                                      Dim valXProxyContext As String

                                                      Dim resXProxyContext As String

                                                                valAccountName = line.GetValue(iAccountName)

                                                                valcn = line.GetValue(icn)

                                                                valUID_Person = line.GetValue(iAccountName)

                                                                valUID_UNSContainerB = "DBApp2/Users"

                                                                valXProxyContext = "DBApp2"

                                                                '

                                                                ' Here is the place to check and change raw data

                                                                '

                                                                lineData.Line = line

     

                                                                Value = valUID_Person

     

                                                                ' Start of convert script for UID_Person

                                                                Value = line.GetValue(iAccountName)

                                                                ' End of convert script for UID_Person

     

                                                                valUID_Person = DbVal.ConvertTo(Of String)(Value)

     

     

                                                                ' Convert raw data to final column data values

                                                                resAccountName = DbVal.ConvertTo(Of String)(columnAccountName.ResolveValue(valAccountName), lineProvider.Culture)

                                                                rescn = DbVal.ConvertTo(Of String)(columncn.ResolveValue(valcn), lineProvider.Culture)

                                                                resUID_Person = DbVal.ConvertTo(Of String)(columnUID_Person.ResolveValue(valUID_Person), lineProvider.Culture)

                                                                resUID_UNSContainerB = DbVal.ConvertTo(Of String)(columnUID_UNSContainerB.ResolveValue(valUID_UNSContainerB), lineProvider.Culture)

                                                                resXProxyContext = DbVal.ConvertTo(Of String)(columnXProxyContext.ResolveValue(valXProxyContext), lineProvider.Culture)

                                                                resUID_Person=Connection.GetSingleProperty("Person", "UID_Person", f.Comparison("CentralAccount", valUID_Person , ValType.String)).ToString

     

                                                                VID_Write2Log(logFile,String.Format("Got referenced uid person as: {0}",resUID_Person))

                                                                '

                                                                ' Here is the place to check and change final column data

                                                                '

                                                                '

                                                                ' Here starts the standard handling. It is recommended to not change anything beyond this point.

                                                                '

                                                                '

                                                                ' Create key for this line

                                                                '

                                                                key = DbVal.ConvertTo(Of String)(resAccountName).ToString

                                                                key = key.Trim

                                                                'VID_Write2Log(logFile,String.Format("key read from DB: {0}",key))

                                                      obj = Nothing

                                                      Dim elem As IColElem = Nothing

                                                      Dim bag As New PropertyBag()

     

                                                      If elemsByKey.TryGetValue(key, elem) Then

                                                                '

                                                                ' Found -> Update

                                                                '

     

                                                                VID_Write2Log(logFile,String.Format("Updating {0}",key))

                                                                ' Element in der Collection für die Übermengenbehandlung markieren

                                                                elem.IsSelected = True

                                                                ' Map values

                                                                Dim found As Boolean = False

                                                                'If DbVal.Compare(elem.GetRaw("cn"), rescn, ValType.String) <> 0 Then

                                                                '          bag.PutValue("cn", rescn)

                                                                '          found = True

                                                                'End If

                                                                If DbVal.Compare(elem.GetRaw("UID_Person"), resUID_Person, ValType.String) <> 0 Then

                                                                          bag.PutValue("UID_Person", resUID_Person)

                                                                          found = True

                                                                End If

                                                                'If DbVal.Compare(elem.GetRaw("UID_UNSContainerB"), resUID_UNSContainerB, ValType.String) <> 0 Then

                                                                '          bag.PutValue("UID_UNSContainerB", resUID_UNSContainerB)

                                                                '          found = True

                                                                'End If

                                                                'If DbVal.Compare(elem.GetRaw("XProxyContext"), resXProxyContext, ValType.String) <> 0 Then

                                                                '          bag.PutValue("XProxyContext", resXProxyContext)

                                                                '          found = True

                                                                'End If

                                                                If found Then

                                                                          ' Create object only when values have changed

                                     

                                                                          obj = elem.Create()

                                                                          If Not obj.IsLoaded Then

                                                                                    obj.Load()

                                                                          End If

                                                                Else

                                                                          counter.Increment(LineType.Unchanged)

                                                                End If

                                                      Else

                                                                '

                                                                ' Not found -> Insert

                                                                '

                                                                VID_Write2Log(logFile,String.Format("Creating user {0}",resAccountName))

                                                                obj = Connection.CreateSingle("UNSAccountB")

                                                                ' Fill keys and values

                                                                bag.PutValue("AccountName", resAccountName)

                                                                bag.PutValue("cn", rescn)

                                                                If resAccountName.ToUpper.StartsWith("Special") Or resAccountName.ToUpper.StartsWith("Control") Then

                                                                          VID_Write2Log(logFile,String.Format("Skipping person association for {0}",resAccountName))

                                                                Else

                                                                          bag.PutValue("UID_Person", resUID_Person)

                                                                End If

                                                                bag.PutValue("UID_UNSContainerB", resUID_UNSContainerB)

                                                                bag.PutValue("XProxyContext", resXProxyContext)

                                                      End If

                                                      '

                                                      ' Additional values can be put into the bag here

                                                      '

     

                                                      If Not obj Is Nothing Then

                                                                If obj.IsDeleted Then

                                                                          ' Recall deleted object

                                                                          obj.Recall()

                                                                End If

                                                                ' Change object

                                                                bag.ChangeObject(obj, True)

                                                                Dim isUpdate As Boolean = obj.IsLoaded

     

                                                                ' Save it

                                                                If obj.IsDifferent Then

                                                                          obj.Save()

     

                                                                          If isUpdate Then

                                                                                    counter.Increment(LineType.Updated)

                                                                          Else

                                                                                    counter.Increment(LineType.Inserted)

                                                                          End If

                                                                Else

                                                                          counter.Increment(LineType.Unchanged)

                                                                End If

                                                                If elem Is Nothing Then

                                                                          ' Include in our collection to avoid double imports of elements

                                                                          Dim keyInsert As String

                                                                          keyInsert = obj.GetValue("AccountName").String

                                                                          colImport.Insert(obj)

                                                                          Dim elemInsert As IColElem = colImport(colImport.Count - 1)

                                                                          elemsByKey(keyInsert) = elemInsert

                                                                          elemInsert.IsSelected = True

                                                                End If

                                                      End If

                                            Catch ex As Exception

                                                      dfImport.Log(MsgSeverity.Serious, #LD("Error in line {0}: {1}", counter(LineType.Total), ViException.ErrorString(ex))#)

                              doNotDelete = True

                                                      counter.Increment(LineType.Error)

                                            End Try

                                            If (counter(LineType.Total) Mod 100) = 0 Then

                                                      dfImport.SetProgressInfo(#LD("{0} lines imported, {1} ignored, {2} inserted, {3} updated, {4} errors", counter(LineType.Total), counter(LineType.Unchanged), counter(LineType.Inserted), counter(LineType.Updated), counter(LineType.Error))#)

                                            End If

                                  Next ' ForEach line

     

            Finally

                If Not logSection Is Nothing Then

                                            logSection.Dispose()

                                            logSection = Nothing

                                  End If

            End Try

                        '

            ' Superset handling

            '

            If StopProcessing Then

                                  dfImport.Log(MsgSeverity.Warning, #LD("No superset handling, because import was stopped.")#)

                        ElseIf doNotDelete Then

                                  dfImport.Log(MsgSeverity.Warning, #LD("There were errors during the parsing of input data. No elements will be deleted to prevent data loss.")#)

                        Else

                                  logSection = dfImport.LogSection(#LD("Removing entries missing in the import")#)

                                  Try

                                            Dim toDelete As New List(Of IColElem)()

                                            For Each elem As IColElem In colImport

                                                      Try

                                                                If elem.IsSelected Then

                                                                          Continue For   ' Found in the import

                                                                End If

                                                                VID_Write2Log(logFile,String.Format("Marking for removal {0}",elem.GetValue("AccountName")))

                                                                toDelete.Add(elem)

                                                      Catch ex As Exception

                                                                dfImport.Log(MsgSeverity.Serious, #LD("Error removing object {0}", elem.Display)#)

                                                                dfImport.LogExecption(ex)

                                                      End Try

                                            Next

                                            For Each elem As IColElem In toDelete

                                                      Dim display As String = Nothing          ' There are no displays in slim collections

                                                      Try

                                                                obj = elem.Create()

                                                                display = obj.Display

                                                                obj.Delete()

                                                                obj.Save()

                                                                VID_Write2Log(logFile,String.Format("Executed removal ok"))

                                                                counter.Increment(LineType.Deleted)

                                                                dfImport.SetProgressInfo(#LD("{0} of {1} deleted", counter(LineType.Deleted), toDelete.Count)#)

                                                      Catch ex As Exception

                                                                If String.IsNullOrEmpty(display) Then

                                                                          display = New DbObjectKey(table, elem).ToXmlString()

                                                                End If

                                                                dfImport.Log(MsgSeverity.Serious, #LD("Error deleting object {0}", display)#)

                                                                dfImport.LogExecption(ex)

     

                                                                counter.Increment(LineType.Error)

                                                      End Try

                                            Next

                                  Finally

                                            If Not logSection Is Nothing Then

                                                      logSection.Dispose()

                                                      logSection = Nothing

                                            End If

                                  End Try

                        End If

        Finally

           

                        Connection.Variables.Remove("FULLSYNC")

        End Try

              Using dfImport.LogSection(#LD("Resultate")#)

                        dfImport.Log(#LD("{0} lines imported", counter(LineType.Total))#)

                        dfImport.Log(#LD("{0} header lines", counter(LineType.Header))#)

                        dfImport.Log(#LD("{0} inserted", counter(LineType.Inserted))#)

                        dfImport.Log(#LD("{0} changed", counter(LineType.Updated))#)

                        dfImport.Log(#LD("{0} deleted", counter(LineType.Deleted))#)

                        dfImport.Log(#LD("{0} not changed", counter(LineType.Unchanged))#)

                        dfImport.Log(#LD("{0} not found", counter(LineType.NotFound))#)

                        dfImport.Log(#LD("{0} empty lines", counter(LineType.Empty))#)

                        dfImport.Log(#LD("{0} errors", counter(LineType.Error))#)

              End Using

    End Sub

Reply
  • Alright Steffen. Here is the first script - the user import script. I have sanitized portions of it to protect the innocent but the entire contents are there.

    #If Not SCRIPTDEBUGGER Then

    References VI.DataImport.dll

    Imports System.Collections.Generic

    Imports System.IO

    Imports System.Globalization

    Imports VI.DB.Specialized

    Imports VI.DataImport

    #End If

    Public Sub TST_DBApp2_Import(ByVal dfImport As DataFileImport)

        ' Standard variables

        Dim logSection As IDisposable

        Dim milliSec As Double = Timer

              Dim logFile As String =Connection.GetConfigParm("Custom\LogFileOutputDirectory") & "\TST_DBApp2_Import_" & Year(Now) & Day(Now) & Hour(Now) & Minute(Now) & Second(Now) & milliSec.ToString & ".log"

        Dim f As ISqlFormatter = Connection.SqlFormatter

              ' Table

        Dim table As TableDef = Connection.Tables("UNSAccountB")

              ' Do not delete any objects, if this marker is set

              Dim doNotDelete As Boolean = False

              ' Line counter

        Dim counter As New LineCounter()

              Dim obj As ISingleDbObject = Nothing

              ' Value provider

              Dim lineData As New LineValueProvider(New String() {"User ID", "User Name", "User Last Updated By", "User Last Updated On", "", "", ""})

              Provider = lineData

              ' Import from an external database

              Dim lineProvider As New DbLineProvider()

              lineProvider.ProviderName = "System.Data.SqlClient.SqlClientFactory, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"

              lineProvider.ConnectionString = Connection.GetConfigParm("Custom\DBApp2\ConnectionString")

              ' SQL statement

              Dim statement As New PlainSqlStatement()

              statement.Statement = "SELECT U.UserId AS [User ID], U.UserName AS [User Name], U.LastUpdateID AS [User Last Updated By], U.LastUpdated AS [User Last Updated On] FROM TST..ssMasUser U"

     

              lineProvider.Statement = statement

     

              '

        ' Configure column resolution

              '

     

        ' Column indices

        Const iAccountName As Integer = 0

        Const icn As Integer = 1

              ' Resolver to get column data from import data

        Dim columnAccountName As IResolveImportValue = New ResolveImportValueSimple("AccountName")

        Dim columncn As IResolveImportValue = New ResolveImportValueSimple("cn")

              ' Build a dictionary: The last parameter forces exceptions when duplicate keys are found

        Dim columnUID_Person As New ResolveImportValueHashed( _

            Connection, _

            ObjectWalker.ColDefs(table, "FK(UID_Person).CentralAccount"), False)

              ' Build a dictionary: The last parameter forces exceptions when duplicate keys are found

        Dim columnUID_UNSContainerB As New ResolveImportValueHashed( _

            Connection, _

            ObjectWalker.ColDefs(table, "FK(UID_UNSContainerB).canonicalname"), False)

        Dim columnXProxyContext As IResolveImportValue = New ResolveImportValueSimple("XProxyContext")

              ' Set connection variables

              Connection.Variables("FULLSYNC") = "true"

        Try

            '

            ' Create a dictionary for the destination table

            '

            Dim colImport As IColDbObject = Connection.CreateCol("UNSAccountB")

            Dim elemsByKey As New Dictionary(Of String, IColElem)(StringComparer.OrdinalIgnoreCase)

                        logSection = dfImport.LogSection(#LD("Bilde Index über bestehende Daten")#)

                        Try

                                  ' Set keys and values as display items to load them with the collection

                                  colImport.Prototype("AccountName").IsDisplayItem = True

                                  colImport.Prototype("cn").IsDisplayItem = True

                                  colImport.Prototype("UID_Person").IsDisplayItem = True

                                  colImport.Prototype("UID_UNSContainerB").IsDisplayItem = True

                                  colImport.Prototype("XProxyContext").IsDisplayItem = True

                                  colImport.Prototype.WhereClause = "xproxycontext = N'DBApp2'"

     

                                  ' Load the collection

                                  colImport.Load(CollectionLoadType.Slim)

                                  ' Put the entries in the dictionary

                                  For Each elem As IColElem In colImport

                                            Dim key As String

                                            key = elem.GetValue("AccountName").ToString

                                            'VID_Write2Log(logFile,String.Format("Processing key: {0}",key))

                                            If elemsByKey.ContainsKey(key) Then

                                                      VID_Write2Log(logFile,String.Format("Duplicate key: {0}",key))

                                                      dfImport.Log(MsgSeverity.Serious, #LD("Duplicate key: {0}", key)#)

                                            Else

                                                      'VID_Write2Log(logFile,String.Format("Adding key {0} to elemsByKey",key))

                                                      elemsByKey.Add(key, elem)

                                            End If

                                  Next

            Finally

                If Not logSection Is Nothing Then

                                            logSection.Dispose()

                                            logSection = Nothing

                                  End If

            End Try

     

                        'VID_Write2Log(logFile,String.Format("---------------Finished processing {0} keys",elemsByKey.Count))

                        logSection = dfImport.LogSection(#LD("Import data from file")#)

            Try

                                  For Each line As Line In lineProvider.GetLines(counter)

                                            ' Pay attention to the Stop flag

                                            If StopProcessing Then

                                                      dfImport.Log(MsgSeverity.Warning, #LD("Abarbeitung wurde gestoppt.")#)

                                                      Exit For

                                            End If

     

                                            Try

                                                      ' Get raw data from the current line

                                                      Dim key As String

                                                      Dim valAccountName As String

                                                      Dim resAccountName As String

                                                      Dim valcn As String

                                                      Dim rescn As String

                                                      Dim valUID_Person As String

                                                      Dim resUID_Person As String

                                                      Dim valUID_UNSContainerB As String

                                                      Dim resUID_UNSContainerB As String

                                                      Dim valXProxyContext As String

                                                      Dim resXProxyContext As String

                                                                valAccountName = line.GetValue(iAccountName)

                                                                valcn = line.GetValue(icn)

                                                                valUID_Person = line.GetValue(iAccountName)

                                                                valUID_UNSContainerB = "DBApp2/Users"

                                                                valXProxyContext = "DBApp2"

                                                                '

                                                                ' Here is the place to check and change raw data

                                                                '

                                                                lineData.Line = line

     

                                                                Value = valUID_Person

     

                                                                ' Start of convert script for UID_Person

                                                                Value = line.GetValue(iAccountName)

                                                                ' End of convert script for UID_Person

     

                                                                valUID_Person = DbVal.ConvertTo(Of String)(Value)

     

     

                                                                ' Convert raw data to final column data values

                                                                resAccountName = DbVal.ConvertTo(Of String)(columnAccountName.ResolveValue(valAccountName), lineProvider.Culture)

                                                                rescn = DbVal.ConvertTo(Of String)(columncn.ResolveValue(valcn), lineProvider.Culture)

                                                                resUID_Person = DbVal.ConvertTo(Of String)(columnUID_Person.ResolveValue(valUID_Person), lineProvider.Culture)

                                                                resUID_UNSContainerB = DbVal.ConvertTo(Of String)(columnUID_UNSContainerB.ResolveValue(valUID_UNSContainerB), lineProvider.Culture)

                                                                resXProxyContext = DbVal.ConvertTo(Of String)(columnXProxyContext.ResolveValue(valXProxyContext), lineProvider.Culture)

                                                                resUID_Person=Connection.GetSingleProperty("Person", "UID_Person", f.Comparison("CentralAccount", valUID_Person , ValType.String)).ToString

     

                                                                VID_Write2Log(logFile,String.Format("Got referenced uid person as: {0}",resUID_Person))

                                                                '

                                                                ' Here is the place to check and change final column data

                                                                '

                                                                '

                                                                ' Here starts the standard handling. It is recommended to not change anything beyond this point.

                                                                '

                                                                '

                                                                ' Create key for this line

                                                                '

                                                                key = DbVal.ConvertTo(Of String)(resAccountName).ToString

                                                                key = key.Trim

                                                                'VID_Write2Log(logFile,String.Format("key read from DB: {0}",key))

                                                      obj = Nothing

                                                      Dim elem As IColElem = Nothing

                                                      Dim bag As New PropertyBag()

     

                                                      If elemsByKey.TryGetValue(key, elem) Then

                                                                '

                                                                ' Found -> Update

                                                                '

     

                                                                VID_Write2Log(logFile,String.Format("Updating {0}",key))

                                                                ' Element in der Collection für die Übermengenbehandlung markieren

                                                                elem.IsSelected = True

                                                                ' Map values

                                                                Dim found As Boolean = False

                                                                'If DbVal.Compare(elem.GetRaw("cn"), rescn, ValType.String) <> 0 Then

                                                                '          bag.PutValue("cn", rescn)

                                                                '          found = True

                                                                'End If

                                                                If DbVal.Compare(elem.GetRaw("UID_Person"), resUID_Person, ValType.String) <> 0 Then

                                                                          bag.PutValue("UID_Person", resUID_Person)

                                                                          found = True

                                                                End If

                                                                'If DbVal.Compare(elem.GetRaw("UID_UNSContainerB"), resUID_UNSContainerB, ValType.String) <> 0 Then

                                                                '          bag.PutValue("UID_UNSContainerB", resUID_UNSContainerB)

                                                                '          found = True

                                                                'End If

                                                                'If DbVal.Compare(elem.GetRaw("XProxyContext"), resXProxyContext, ValType.String) <> 0 Then

                                                                '          bag.PutValue("XProxyContext", resXProxyContext)

                                                                '          found = True

                                                                'End If

                                                                If found Then

                                                                          ' Create object only when values have changed

                                     

                                                                          obj = elem.Create()

                                                                          If Not obj.IsLoaded Then

                                                                                    obj.Load()

                                                                          End If

                                                                Else

                                                                          counter.Increment(LineType.Unchanged)

                                                                End If

                                                      Else

                                                                '

                                                                ' Not found -> Insert

                                                                '

                                                                VID_Write2Log(logFile,String.Format("Creating user {0}",resAccountName))

                                                                obj = Connection.CreateSingle("UNSAccountB")

                                                                ' Fill keys and values

                                                                bag.PutValue("AccountName", resAccountName)

                                                                bag.PutValue("cn", rescn)

                                                                If resAccountName.ToUpper.StartsWith("Special") Or resAccountName.ToUpper.StartsWith("Control") Then

                                                                          VID_Write2Log(logFile,String.Format("Skipping person association for {0}",resAccountName))

                                                                Else

                                                                          bag.PutValue("UID_Person", resUID_Person)

                                                                End If

                                                                bag.PutValue("UID_UNSContainerB", resUID_UNSContainerB)

                                                                bag.PutValue("XProxyContext", resXProxyContext)

                                                      End If

                                                      '

                                                      ' Additional values can be put into the bag here

                                                      '

     

                                                      If Not obj Is Nothing Then

                                                                If obj.IsDeleted Then

                                                                          ' Recall deleted object

                                                                          obj.Recall()

                                                                End If

                                                                ' Change object

                                                                bag.ChangeObject(obj, True)

                                                                Dim isUpdate As Boolean = obj.IsLoaded

     

                                                                ' Save it

                                                                If obj.IsDifferent Then

                                                                          obj.Save()

     

                                                                          If isUpdate Then

                                                                                    counter.Increment(LineType.Updated)

                                                                          Else

                                                                                    counter.Increment(LineType.Inserted)

                                                                          End If

                                                                Else

                                                                          counter.Increment(LineType.Unchanged)

                                                                End If

                                                                If elem Is Nothing Then

                                                                          ' Include in our collection to avoid double imports of elements

                                                                          Dim keyInsert As String

                                                                          keyInsert = obj.GetValue("AccountName").String

                                                                          colImport.Insert(obj)

                                                                          Dim elemInsert As IColElem = colImport(colImport.Count - 1)

                                                                          elemsByKey(keyInsert) = elemInsert

                                                                          elemInsert.IsSelected = True

                                                                End If

                                                      End If

                                            Catch ex As Exception

                                                      dfImport.Log(MsgSeverity.Serious, #LD("Error in line {0}: {1}", counter(LineType.Total), ViException.ErrorString(ex))#)

                              doNotDelete = True

                                                      counter.Increment(LineType.Error)

                                            End Try

                                            If (counter(LineType.Total) Mod 100) = 0 Then

                                                      dfImport.SetProgressInfo(#LD("{0} lines imported, {1} ignored, {2} inserted, {3} updated, {4} errors", counter(LineType.Total), counter(LineType.Unchanged), counter(LineType.Inserted), counter(LineType.Updated), counter(LineType.Error))#)

                                            End If

                                  Next ' ForEach line

     

            Finally

                If Not logSection Is Nothing Then

                                            logSection.Dispose()

                                            logSection = Nothing

                                  End If

            End Try

                        '

            ' Superset handling

            '

            If StopProcessing Then

                                  dfImport.Log(MsgSeverity.Warning, #LD("No superset handling, because import was stopped.")#)

                        ElseIf doNotDelete Then

                                  dfImport.Log(MsgSeverity.Warning, #LD("There were errors during the parsing of input data. No elements will be deleted to prevent data loss.")#)

                        Else

                                  logSection = dfImport.LogSection(#LD("Removing entries missing in the import")#)

                                  Try

                                            Dim toDelete As New List(Of IColElem)()

                                            For Each elem As IColElem In colImport

                                                      Try

                                                                If elem.IsSelected Then

                                                                          Continue For   ' Found in the import

                                                                End If

                                                                VID_Write2Log(logFile,String.Format("Marking for removal {0}",elem.GetValue("AccountName")))

                                                                toDelete.Add(elem)

                                                      Catch ex As Exception

                                                                dfImport.Log(MsgSeverity.Serious, #LD("Error removing object {0}", elem.Display)#)

                                                                dfImport.LogExecption(ex)

                                                      End Try

                                            Next

                                            For Each elem As IColElem In toDelete

                                                      Dim display As String = Nothing          ' There are no displays in slim collections

                                                      Try

                                                                obj = elem.Create()

                                                                display = obj.Display

                                                                obj.Delete()

                                                                obj.Save()

                                                                VID_Write2Log(logFile,String.Format("Executed removal ok"))

                                                                counter.Increment(LineType.Deleted)

                                                                dfImport.SetProgressInfo(#LD("{0} of {1} deleted", counter(LineType.Deleted), toDelete.Count)#)

                                                      Catch ex As Exception

                                                                If String.IsNullOrEmpty(display) Then

                                                                          display = New DbObjectKey(table, elem).ToXmlString()

                                                                End If

                                                                dfImport.Log(MsgSeverity.Serious, #LD("Error deleting object {0}", display)#)

                                                                dfImport.LogExecption(ex)

     

                                                                counter.Increment(LineType.Error)

                                                      End Try

                                            Next

                                  Finally

                                            If Not logSection Is Nothing Then

                                                      logSection.Dispose()

                                                      logSection = Nothing

                                            End If

                                  End Try

                        End If

        Finally

           

                        Connection.Variables.Remove("FULLSYNC")

        End Try

              Using dfImport.LogSection(#LD("Resultate")#)

                        dfImport.Log(#LD("{0} lines imported", counter(LineType.Total))#)

                        dfImport.Log(#LD("{0} header lines", counter(LineType.Header))#)

                        dfImport.Log(#LD("{0} inserted", counter(LineType.Inserted))#)

                        dfImport.Log(#LD("{0} changed", counter(LineType.Updated))#)

                        dfImport.Log(#LD("{0} deleted", counter(LineType.Deleted))#)

                        dfImport.Log(#LD("{0} not changed", counter(LineType.Unchanged))#)

                        dfImport.Log(#LD("{0} not found", counter(LineType.NotFound))#)

                        dfImport.Log(#LD("{0} empty lines", counter(LineType.Empty))#)

                        dfImport.Log(#LD("{0} errors", counter(LineType.Error))#)

              End Using

    End Sub

Children
No Data