2017-03-01 8 views
0

문제 롤백, 더 이상 사용할 수, 완료 없다 :이 오류가 팝업 원인을 모르겠습니다SqlTransaction 내가 한 동안이 오류 메시지가 직면하고있다

The SqlTransaction has completed; it is no longer usable.

를, 내가 시도 설정 SQL 제한 시간이 무한대입니다.

내 코드 구조 때문입니까?

사용자의 소그룹 일 때 발생하지 않지만 사용자 그룹이 많을 때 자주 발생합니다.

Public Function PostCustomerSet(ByVal ds As CustomerHeaderDetailDataSet, ByVal Table As String, ByRef SessionKeys As String, ByRef errMsg As String, ByVal SubmitType As Integer, ByVal callWrapper As Boolean) As String 
    errMsg = Nothing 
    Dim newkey As PrimaryKey 
    Dim oldkey As PrimaryKey 
    Try 
     transaction = EnterpriseUtils.StartTransaction(Connection1, m_Dict) 
     If ds.CustomerHeader.Rows.Count > 0 Then 
      Dim SessionKey As PrimaryKey = PrimaryKey.FromString(SessionKeys) 
      Dim CustomerHeaderKey As PrimaryKey = EnterpriseUtils.VerifyDataRowKeys(ds.CustomerHeader.Rows(0), SessionKey, SubmitType) 
      Dim OldCustomerHeaderKey As PrimaryKey = New PrimaryKey(CustomerHeaderKey) 
      newkey = CustomerHeaderKey 
      oldkey = OldCustomerHeaderKey 

      If CustomerHeaderKey Is Nothing Then 
       Return Nothing 
      Else 
       If ds.CustomerHeader.Rows.Count > 0 Then 'check if record was not deleted during update 
        CustomerHeaderKey.Update(ds.CustomerHeader(0)) 
        If SubmitType = 1 Then 
         EnterpriseUtils.UpdateTemporaryLinks("CustomerNumber", CustomerHeaderKey, OldCustomerHeaderKey, "CustomerDetail", transaction) 
         EnterpriseUtils.UpdateTemporaryLinks("CustomerNumber", CustomerHeaderKey, OldCustomerHeaderKey, "CustomerMultiPayments", transaction) 
        End If 


        If callWrapper AndAlso ds.CustomerHeader(0).CustomerNumber.ToUpper <> "DEFAULT" Then 
         Dim Command As SqlCommand = New SqlCommand("enterprise.Customer_Control", Connection1) 
         Command.CommandType = CommandType.StoredProcedure 
         Command.Transaction = transaction 
         Dim parameter As SqlParameter 
         '@CompanyID 
         parameter = New SqlParameter("@CompanyID", SqlDbType.NVarChar, 36) 
         parameter.Value = ds.CustomerHeader(0).CompanyID 
         Command.Parameters.Add(parameter) 
         'DivisionID 
         parameter = New SqlParameter("@DivisionID", SqlDbType.NVarChar, 36) 
         parameter.Value = ds.CustomerHeader(0).DivisionID 
         Command.Parameters.Add(parameter) 
         '@DepartmentID 
         parameter = New SqlParameter("@DepartmentID", SqlDbType.NVarChar, 36) 
         parameter.Value = ds.CustomerHeader(0).DepartmentID 
         Command.Parameters.Add(parameter) 
         '@DocumentNumber 
         parameter = New SqlParameter("@DocumentNumber", SqlDbType.NVarChar, 36) 
         parameter.Value = ds.CustomerHeader(0).CustomerNumber 
         Command.Parameters.Add(parameter) 
         Command.ExecuteNonQuery() 
        End If 
       End If 
       transaction.Commit() 
       transaction = Nothing 
       Return CustomerHeaderKey.ToString() 
      End If 
     ElseIf ds.CustomerDetail.Count > 0 Then 
      CustomerDetail_Adapter.Update(ds.CustomerDetail) 
      transaction.Commit() 
      transaction = Nothing 
     ElseIf ds.CustomerMiscCharges.Count > 0 Then 
      CustomerMiscCharges_Adapter.Update(ds.CustomerMiscCharges) 
      transaction.Commit() 
      transaction = Nothing 
     ElseIf ds.CustomerMultiPayments.Count > 0 Then 
      CustomerMultiPayment_Adapter.Update(ds.CustomerMultiPayments) 
      transaction.Commit() 
      transaction = Nothing 
     End If 
     Return Nothing  
    Catch e As SqlException 
     errMsg = "Please contact your system administrator. (code number: " + e.Number + ")" 'Message + ")" 
     WebUtils.ProcessError(e, errMsg, EDIErrorType.SendEmailNotification Or EDIErrorType.WriteLog) 
     Return Nothing 
    Catch e As Exception 
     errMsg = e.Message 
     WebUtils.ProcessError(e, errMsg, EDIErrorType.SendEmailNotification Or EDIErrorType.WriteLog) 
     Return Nothing 
    Finally 
     If Not transaction Is Nothing Then 
      transaction.Rollback() 
     End If 
     If Connection1.State = ConnectionState.Open Then 
      Connection1.Close() 
     End If 
    End Try 
End Function 

누구나 내가 뭘 잘못했는지 힌트를 줄 수 있습니까? 고급의

감사합니다.

답변

0

당신은이 문제를 일으키는 어떤

transaction.Commit() 


transaction = Nothing를 설정하는, 당신은 마지막 방법 후 아무것도로 이것을 설정해야합니다.

Public Function PostCustomerSet(ByVal ds As CustomerHeaderDetailDataSet, ByVal Table As String, ByRef SessionKeys As String, ByRef errMsg As String, ByVal SubmitType As Integer, ByVal callWrapper As Boolean) As String 
errMsg = Nothing 
Dim newkey As PrimaryKey 
Dim oldkey As PrimaryKey 
Try 
    transaction = EnterpriseUtils.StartTransaction(Connection1, m_Dict) 
    If ds.CustomerHeader.Rows.Count > 0 Then 
     Dim SessionKey As PrimaryKey = PrimaryKey.FromString(SessionKeys) 
     Dim CustomerHeaderKey As PrimaryKey = EnterpriseUtils.VerifyDataRowKeys(ds.CustomerHeader.Rows(0), SessionKey, SubmitType) 
     Dim OldCustomerHeaderKey As PrimaryKey = New PrimaryKey(CustomerHeaderKey) 
     newkey = CustomerHeaderKey 
     oldkey = OldCustomerHeaderKey 

     If CustomerHeaderKey Is Nothing Then 
      Return Nothing 
     Else 
      If ds.CustomerHeader.Rows.Count > 0 Then 'check if record was not deleted during update 
       CustomerHeaderKey.Update(ds.CustomerHeader(0)) 
       If SubmitType = 1 Then 
        EnterpriseUtils.UpdateTemporaryLinks("CustomerNumber", CustomerHeaderKey, OldCustomerHeaderKey, "CustomerDetail", transaction) 
        EnterpriseUtils.UpdateTemporaryLinks("CustomerNumber", CustomerHeaderKey, OldCustomerHeaderKey, "CustomerMultiPayments", transaction) 
       End If 


       If callWrapper AndAlso ds.CustomerHeader(0).CustomerNumber.ToUpper <> "DEFAULT" Then 
        Dim Command As SqlCommand = New SqlCommand("enterprise.Customer_Control", Connection1) 
        Command.CommandType = CommandType.StoredProcedure 
        Command.Transaction = transaction 
        Dim parameter As SqlParameter 
        '@CompanyID 
        parameter = New SqlParameter("@CompanyID", SqlDbType.NVarChar, 36) 
        parameter.Value = ds.CustomerHeader(0).CompanyID 
        Command.Parameters.Add(parameter) 
        'DivisionID 
        parameter = New SqlParameter("@DivisionID", SqlDbType.NVarChar, 36) 
        parameter.Value = ds.CustomerHeader(0).DivisionID 
        Command.Parameters.Add(parameter) 
        '@DepartmentID 
        parameter = New SqlParameter("@DepartmentID", SqlDbType.NVarChar, 36) 
        parameter.Value = ds.CustomerHeader(0).DepartmentID 
        Command.Parameters.Add(parameter) 
        '@DocumentNumber 
        parameter = New SqlParameter("@DocumentNumber", SqlDbType.NVarChar, 36) 
        parameter.Value = ds.CustomerHeader(0).CustomerNumber 
        Command.Parameters.Add(parameter) 
        Command.ExecuteNonQuery() 
       End If 
      End If 
      transaction.Commit() 
      transaction = Nothing 
      Return CustomerHeaderKey.ToString() 
     End If 
    ElseIf ds.CustomerDetail.Count > 0 Then 
     CustomerDetail_Adapter.Update(ds.CustomerDetail) 
     transaction.Commit() 

    ElseIf ds.CustomerMiscCharges.Count > 0 Then 
     CustomerMiscCharges_Adapter.Update(ds.CustomerMiscCharges) 
     transaction.Commit() 

    ElseIf ds.CustomerMultiPayments.Count > 0 Then 
     CustomerMultiPayment_Adapter.Update(ds.CustomerMultiPayments) 
     transaction.Commit() 

    End If 
    Return Nothing  
Catch e As SqlException 
    errMsg = "Please contact your system administrator. (code number: " + e.Number + ")" 'Message + ")" 
    WebUtils.ProcessError(e, errMsg, EDIErrorType.SendEmailNotification Or EDIErrorType.WriteLog) 
    Return Nothing 
Catch e As Exception 
    errMsg = e.Message 
    WebUtils.ProcessError(e, errMsg, EDIErrorType.SendEmailNotification Or EDIErrorType.WriteLog) 
    Return Nothing 
Finally 
    If Not transaction Is Nothing Then 
     transaction.Rollback() 
    End If 
    If Connection1.State = ConnectionState.Open Then 
     Connection1.Close() 
    End If 
End Try 
transaction = Nothing 

최종 기능

+0

안녕 케쉬, 의견을 보내 주셔서 감사합니다! 나는 그것을 시도하고 알려 줄 것입니다 –

+0

안녕하세요 Rakesh, 나는 당신의 의견을 물어보고 싶은 질문이 있습니다. SQL에서 내 저장 프로 시저가 이미 저장 프로 시저의 끝에서, 이런 식으로 뭔가를 롤백 (rollback)을 구현했습니다 : WriteError : ELSE @@ TRANCOUNT <2 \t ROLLBACK TRAN T1 IF \t TRAN T1이 난 아직이 거래가 필요하십니까 COMMIT VB.net에서 .rollback? 고맙습니다. –

+0

아니, 당신이 잘해야한다, 당신 BeginTrans 또는 롤백 코드에서 호출 할 필요가 없습니다. –