我有一个用于执行查询执行循环的代码片段,我将在此处粘贴。
Do While Not Rs1.EOF
OutFoundBit = False
AckedFoundBit = False
If Rs1.Fields(2).Value = "InAlm" And SearchingBit = False And Rs1.Fields(9).Value = False Then
temp_TagName = Rs1.Fields(3).Value
temp_Severity = Rs1.Fields(4).Value
temp_TimeStmp = Rs1.Fields(0).Value
UpdateCheckFieldsSQLStr = "UPDATE tbl_Alarm_Log_Comments SET CheckFields = 'TRUE' WHERE TimeStmp = '" & Rs1.Fields(0).Value & "' AND MilliTime = '" & Rs1.Fields(1).Value & "' AND TagName = '" & Rs1.Fields(3).Value & "'"
temp_Rs.Open UpdateCheckFieldsSQLStr, cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockUnspecified
Rs1.MovePrevious
SearchingBit = True
CurrentProcessedRow = Rs1.Bookmark
CountToLoopUp = Rs1.Bookmark
Else
Rs1.MoveNext
End If
If SearchingBit = True Then
For i = 0 To CountToLoopUp - 1
If (Rs1.Fields(2).Value = "OutAl") And Rs1.Fields(9).Value = False And temp_TagName = Rs1.Fields(3).Value Then
UpdateFoundTagSQLStr = "UPDATE tbl_Alarm_Log_Comments SET Severity = '" & temp_Severity & "', CheckFields = 'TRUE' WHERE TimeStmp = '" & Rs1.Fields(0).Value & "' AND TagName = '" & temp_TagName & "'"
temp_Rs.Open UpdateFoundTagSQLStr, cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockUnspecified
OutFoundBit = True
End If
If (Rs1.Fields(2).Value = "Acked") And Rs1.Fields(9).Value = False And temp_TagName = Rs1.Fields(3).Value Then
UpdateFoundTagSQLStr = "UPDATE tbl_Alarm_Log_Comments SET Severity = '" & temp_Severity & "', CheckFields = 'TRUE' WHERE TimeStmp = '" & Rs1.Fields(0).Value & "' AND TagName = '" & temp_TagName & "'"
temp_Rs.Open UpdateFoundTagSQLStr, cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockUnspecified
AckedFoundBit = True
End If
If OutFoundBit = True And AckedFoundBit = True Then
SearchingBit = False
Rs1.Close
Rs1.Open "SELECT * FROM Tbl_Alarm_Log_Comments", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockUnspecified
Rs1.Bookmark = CurrentProcessedRow + 1
Exit For
End If
If i = CountToLoopUp - 1 Then
SearchingBit = False
Rs1.Close
Rs1.Open "SELECT * FROM Tbl_Alarm_Log_Comments", cn, ADODB.CursorTypeEnum.adOpenDynamic, ADODB.LockTypeEnum.adLockUnspecified
Rs1.Bookmark = CurrentProcessedRow + 1
Exit For
End If
Rs1.MovePrevious
Next
End If
Loop
我遇到的问题是,当手动运行时,意味着我逐个逐步执行,它可以正常工作。但如果我让它自由运行,它会挂起VB6应用程序。所以一个很好的猜测是我在sql服务器上过快地抛出太多查询。
你们有没有想过如何以更有效的方式做到这一点并解决这个问题?
提前致谢!