Hello all,
I have a bit of code that uses collections and transactions with a backend SQL server that I don't have access to. The database tracks installed software on computers. The software information comes from an external script and is saved as a delimited text file. It is then parsed and put into custom objects that are then put into collections. A computer can have anywhere from 200 to 500 entries to be uploaded if they are not already in the DB. To make this process faster I am attempting to use transactions as the increase in perfomence is almost 10 fold. However, the transaction is causing my code to break with a
"Run-time error '3420':
Object invalid or no longer set.
I have searched all over google and have yet to figure this one out. Any help or insight would be appricated.
The following is the code that causes troubles. I have cut the beginning of the code to keep it short, but all objects are properly Dim'd and set. This code works fine with the WrkSpace.BeginTrans and WrkSpace.CommitTrans commeted out.
I have a bit of code that uses collections and transactions with a backend SQL server that I don't have access to. The database tracks installed software on computers. The software information comes from an external script and is saved as a delimited text file. It is then parsed and put into custom objects that are then put into collections. A computer can have anywhere from 200 to 500 entries to be uploaded if they are not already in the DB. To make this process faster I am attempting to use transactions as the increase in perfomence is almost 10 fold. However, the transaction is causing my code to break with a
"Run-time error '3420':
Object invalid or no longer set.
I have searched all over google and have yet to figure this one out. Any help or insight would be appricated.
The following is the code that causes troubles. I have cut the beginning of the code to keep it short, but all objects are properly Dim'd and set. This code works fine with the WrkSpace.BeginTrans and WrkSpace.CommitTrans commeted out.
Code:
Dim db As Database
Set db = DBEngine(0)(0)
Dim rs As DAO.Recordset2
Dim HyenaXPWSTable As DAO.Recordset2
Dim WorkstationRST As DAO.Recordset2
'<-Snip->
Set HyenaXPWSTable = db.OpenRecordset("dbo_HYENA_XP_WRKSTN", dbOpenDynaset, dbSeeChanges)
Set HyenaAppsRST = db.OpenRecordset("dbo_HYENA_APPLICATIONS", dbOpenDynaset, dbSeeChanges)
'**************************************************************************
' Process each Workstation and add data to the db as needed.
'**************************************************************************
'On Error GoTo TransactionError
For Each WorkstationElement In WorkstationsCollection
WrkSpace.BeginTrans
' Is this row already in the appropriate Hyena_XPWorkstation or Hyena_Win7Workstation table? If not, add it.
FirstChar = Mid(WorkstationElement.Name, 1, 1)
'Need to do: -Get Computers actually in scope-
If FirstChar = "7" Then
InsTable = "dbo_Hyena_W7_Wrkstn"
Else
InsTable = "dbo_Hyena_XP_Wrkstn"
End If
For Each SoftwareElement In WorkstationElement.SoftwareCollection
Debug.Print WorkstationElement.Name & " " & SoftwareElement.RegistryKeyName
'Dim rs As DAO.Recordset2
' Is this app in the known list? If not, add it.
strSQL = "SELECT * FROM dbo_Hyena_Applications WHERE dbo_Hyena_Applications![HYENA_APPL_ID] = """ & SoftwareElement.UniqueKeyName & """"
Set rs = db.OpenRecordset(strSQL, dbOpenSnapshot, dbSeeChanges)
'*******************************************************************
rs.MoveLast '<- The Code stops here on the second WorkstationElement for the first SoftwareElement
'*******************************************************************
If rs.Recordcount < 1 Then
AppMatchID = "NotMatch"
' If adding, does it have characteristics of things we filter automatically? If so, filter on find and Build Sheet. Start with false unless overruled.
FilterOnXPFind = 0
' If Publisher is Microsoft
If SoftwareElement.Publisher = "Microsoft Corporation" Then
'and first two characters of RegKeyName = KB or and DisplayName contains Security Update
RegKeyStart = Mid(SoftwareElement.RegistryKeyName, 1, 2)
If RegKeyStart = "KB" Or InStr(1, "Security Update", DisplayName, vbTextCompare) Then
FilterOnXPFind = 1
End If
End If
' If DisplayName is Null or space filter.
If IsNull(SoftwareElement.DisplayName) Or SoftwareElement.DisplayName = " " Then
FilterOnXPFind = 1
End If
' If we haven't filtered it, does it match something that Applications knows about?
If FilterOnXPFind < 1 Then
' Look up in Applications and match display version and display name
rsalucount = 0
stralu = "SELECT ID FROM dbo_Applications WHERE App_Name = '" & SoftwareElement.DisplayName & "' AND App_Version = '" & SoftwareElement.DisplayVersion & "'"
Set rsalu = db.OpenRecordset(stralu, dbOpenDynaset, dbSeeChanges)
If rsalu.Recordcount > 0 Then
rsalu.MoveFirst
MatchID = rsalu!ID
AppMatchID = "Matched"
End If
'rsalu.Close
End If
' Add it to Hyena_Applications.
With HyenaAppsRST
.AddNew
HyenaAppsRST![HYENA_APPL_ID] = SoftwareElement.UniqueKeyName
HyenaAppsRST![REG_KEY_NM] = SoftwareElement.RegistryKeyName
HyenaAppsRST![APPL_VER_MJR] = SoftwareElement.VersionMajor
HyenaAppsRST![APPL_VER_MNR] = SoftwareElement.VersionMinor
HyenaAppsRST![PUBLSHR] = SoftwareElement.Publisher
HyenaAppsRST![dsply_nm] = SoftwareElement.DisplayName
HyenaAppsRST![dsply_ver] = SoftwareElement.DisplayVersion
HyenaAppsRST![FLTR_ON_XP_FIND] = FilterOnXPFind
If Not IsNull(MatchID) And AppMatchID = "Matched" Then
HyenaAppsRST!APPL_ID = MatchID
End If
.Update
NewAppCount = NewAppCount + 1
End With
End If
'rs.Close
strWSQ = "SELECT * FROM " & InsTable & " WHERE HYENA_APPL_ID = '" & SoftwareElement.UniqueKeyName & "' AND WRKSTN_NM = '" & WorkstationElement.Name & "'"
Set rsq2 = db.OpenRecordset(strWSQ, dbOpenDynaset, dbSeeChanges)
If rsq2.Recordcount < 1 Then
'Set HyenaXPWSTable = db.OpenRecordset("dbo_HYENA_XP_WRKSTN", dbOpenDynaset, dbSeeChanges)
With HyenaXPWSTable
.AddNew
HyenaXPWSTable![HYENA_APPL_ID] = SoftwareElement.UniqueKeyName
HyenaXPWSTable![WRKSTN_NM] = WorkstationElement.Name
HyenaXPWSTable![DT_LAST_SCNND] = Date
HyenaXPWSTable![MGR_APPRV_NOT_REQR_FLG] = 0
HyenaXPWSTable![MGR_APPRV_RSPNS_CD] = Null
.Update
End With
'HyenaXPWSTable.Close
ElseIf rsq2.Recordcount = 1 Then
rsq2.Edit
rsq2![DT_LAST_SCNND] = Date
rsq2.Update
End If
'rsq2.Close
numLines = numLines + 1
SysCmd acSysCmdSetStatus, "Processed " & CStr(numLines) & " lines of Hyena data..."
DoEvents
Next SoftwareElement
'Stop
'Tell the dbo_WRKSTN table when the last Hyena Capture date was for a workstation
Set WorkstationRST = db.OpenRecordset("SELECT * FROM dbo_WRKSTN WHERE WRKSTN_NM = """ & WorkstationElement.Name & """;", dbOpenDynaset, dbSeeChanges)
If Not WorkstationRST.EOF Then
If Nz(WorkstationRST![HYENA_DATA_CAPTR_DT], #1/1/1900#) <> Date Then
WorkstationRST.Edit
WorkstationRST![HYENA_DATA_CAPTR_DT] = Date
WorkstationRST.Update
'WrkSpace.CommitTrans
'WrkSpace.BeginTrans
End If
End If
'WorkstationRST.Close
Stop
WrkSpace.CommitTrans
DoEvents
Next WorkstationElement