我有一个存储过程,最多可能需要一个小时才能处理大量数据。如果用户关闭浏览器并返回该页面,则我正在运行检查以查看存储的proc是否仍在运行。如果是这样,则不要允许他们与存储的proc建立另一个连接,而应重新连接到现有的存储的proc数据集。
我正在传递一个employeeId和companyId并检查存储过程中的完成时间,以确定其是否完成。如果不是,那么我不调用该方法来启动另一个连接。相反,我希望能够以某种方式重新连接并从对db的原始调用中检索数据。
Protected Sub btnValidateRule_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnValidateRule.Click
Dim guid As Guid = Guid.NewGuid()
Session.SessionId = guid.ToString
Dim isComplete As Boolean = CheckRunningProgress()
If isComplete = True Then
GetEmployeeByRule(Session.SessionId)
End If
End Sub
Private Function CheckRunningProgress() As Boolean
Dim elig As New Obj.Eligibility()
Dim sqlFilter As String = String.Empty
Dim company As New Obj.Company()
Dim dsRunningProcess As DataSet = company.Get_Current_Running_Process_By_Session(Session.AdminId, Session.CompanyId)
If dsRunningProcess.Tables(0).Rows.Count > 0 Then
Dim currentCount As Integer = 0
Dim totalExpected As Integer = 0
Dim percent As Integer = 0
Dim endTime As String = ""
endTime = dsRunningProcess.Tables(0).Rows(0)("EndTime").ToString()
currentCount = dsRunningProcess.Tables(0).Rows(0)("CurrentCount")
totalExpected = dsRunningProcess.Tables(0).Rows(0)("TotalExpected")
percent = (currentCount / totalExpected) * 100
If percent <> 100 AndAlso endTime = "" Then
Return False
End If
Else
Return True
End If
End Function
Private Sub GetEmployeeByRule(ByVal sessionId As String)
Dim elig As New Obj.Eligibility()
Dim sqlFilter As String = String.Empty
Dim company As New Obj.Company()
Dim typeID As Integer = 0
Dim totalEmployees As Integer = 0
Dim failedEmployees As Integer = 0
Dim passedEmployees As Integer = 0
sqlFilter = elig.Get_EligibilityRule_Filter(ViewState("EligibilityRule_ID"), sqlFilter)
Dim dsEmps As DataSet = company.Get_All_Employees(Session("Company_ID"))
totalEmployees = dsEmps.Tables(0).Rows.Count
Dim dsEmpsByRule As DataSet = company.Get_All_Employees_By_Rule(Session("Company_ID"), sqlFilter, Session.AdminId, typeID, sessionId)
For Each dsRow As DataRow In dsEmpsByRule.Tables(0).Rows
If dsRow("Status").ToString.Trim.ToLower.Equals("passed") Then
passedEmployees += 1
Else
failedEmployees += 1
End If
Next
Dim dtEmpsByRule As DataTable = dsEmpsByRule.Tables(0)
dtEmpsByRule.DefaultView.Sort = "Status DESC"
EmployeesGrid.DataSource = dtEmpsByRule
EmployeesGrid.DataBind()
lblTotalEmps.Text = "Employees Tested: " + totalEmployees.ToString() + " | Passed: " + passedEmployees.ToString() + " | Failed: " + failedEmployees.ToString()
End Sub
就目前情况而言,我从CheckRunningProcess()返回了一个错误的布尔值,这是正确的,但随后该子项才结束并退出。我想以某种方式重新插入到现有存储的proc数据集结果中并返回它们。这样,用户可以离开并返回长时间运行的数据库调用。