1

프레임 워크 1.1에서 VS 2003으로 작성된 VB NET 웹 응용 프로그램에서 다음 오류가 발생합니다. 웹 응용 프로그램은 Windows Server 2000, IIS 5에서 실행되며 동일한 컴퓨터에서 실행되는 SQL Server 2000 데이터베이스에서 읽고 있습니다.SQL Server 2000의 신비한 제약 문제

System.Data.ConstraintException : 제약 조건을 활성화하지 못했습니다. 하나 또는 개의 행에 null이 아닌 고유 키 또는 외부 키 제약 조건을 위반하는 값이 있습니다. System.Data.DataTable.EndLoadData에서 System.Data.DataSet.EnableConstraints() System.Data.DataSet.set_EnforceConstraints에서 ( 부울 값)에 System.Data.DataSet.FailedEnableConstraints() (AT)
System.Data.Common.DbDataAdapter.Fill에서 System.Data.Common.DbDataAdapter.FillFromReader에서 (객체 데이터, 문자열 srcTable, IDataReader에 DataReader를, INT32 startRecord, INT32 을 MaxRecords, DataColumn에 parentChapterColumn, 객체 parentChapterValue) (DataSet dataSet, String s rcTable, IDataReader에 DataReader를, INT32 startRecord, INT32 시스템에서 System.Data.Common.DbDataAdapter.FillFromCommand (객체 데이터, INT32 startRecord, INT32 을 MaxRecords, 문자열 srcTable, 에 IDbCommand 명령, CommandBehavior를 행동)에서 을 MaxRecords) .Data.Common.DbDataAdapter.Fill (데이터 집합 데이터 집합 INT32 startRecord, INT32 을 MaxRecords, 문자열 srcTable, 에 IDbCommand 명령, CommandBehavior를 행동) System.Data.Common.DbDataAdapter.Fill에서 (데이터 집합 와 DataSet)

웹 응용 프로그램의 부하가 높을 때 문제가 나타납니다. 볼륨이 낮을 때 시스템은 잘 실행되지만 요청 수가 많아지면 시스템은 위의 예외 메시지로 들어오는 요청을 거부하기 시작합니다. 문제가 발생하면 거의 모든 요청이 실제로 처리되어 정상적으로 처리됩니다. 매 30 초마다 약 2 개가 처리됩니다. SQL Server를 다시 시작하거나 IIS를 다시 설정할 때까지 대부분의 요청이 실패합니다. 그런 다음 시스템은 요청 처리를 정상적으로 시작하고 잠시 후 동일한 오류를 던지기 시작합니다.

데이터 어댑터가 강력한 형식의 데이터 집합을 채우기 위해 SELECT 문에 대해 Fill() 메서드를 실행하면 오류가 발생합니다. 데이터 집합은 주어진 데이터를 좋아하지 않으며이 예외를 throw합니다. 이 오류는 여러 테이블에서 작동하는 다양한 SELECT 문에서 발생합니다.

데이터 집합을 다시 생성하고 관련 제약 조건과 데이터를 읽을 테이블을 확인했습니다. 데이터 셋 정의와 테이블에있는 데이터 모두 괜찮습니다.

인정 하듯이, 를 실행하는 하드웨어 모두 웹 응용 프로그램 및 SQL Server 2000은 현재 수신 들어오는 요청의 수를 고려하고, 심각하게 구식이다. SQL Server에서 소비하는 RAM 양은 동적으로 할당되며 최대 시간에 SQL Server는 서버에서 총 3.5GB 중에서 최대 2.8GB를 소비 할 수 있습니다.

처음에는 일종의 인덱스 또는 데이터베이스 손상이 의심되었지만 DBCC CHECKDB를 실행 한 후 데이터베이스에서 오류가 발견되지 않았습니다.그래서 지금이 오류가 시스템의 하드웨어 제한으로 인한 것인지 궁금합니다. SQL Server가 데이터 집합에 전달해야하는 데이터를 어떻게 든 엉켜서 데이터 유형/길이 불일치로 인해 제약 조건 위반을 초래할 수 있습니까?

검색된 데이터 세트 테이블에서 데이터 행의 RowError 메시지에 액세스하려고 시도했지만 빈 문자열이 계속 나타납니다. 나는 해당 데이터 테이블에 대해 HasErrors = true를 알고 있습니다. 나는 EnableConstraints = false를 설정하지 않았으며, 그렇게하고 싶지 않습니다. 사전에

감사합니다.

광선

답변

0

유용한 진단 오류 메시지가 부족합니다. 필자는 쓸데없는 일반적인 오류 메시지를 제공하는 대신 제약 조건을 알려주는 메서드가 포함 된 클래스를 작성했습니다. 다음과 같은 방법으로 메소드를 사용합니다.

Dim ds As New dsMyDataset 

'Turn off constraints during the data load' 
DatasetAnalyzer.DatasetAnalyzer_Init(ds) 

'Ready to fill one or more tables' 
Dim da1 As New dsMyDatasetTableAdapters.Table1TableAdapter 
da1.Fill(ds.Table1) 

'Checks relationships and constraints before turning them back on.' 
DatasetAnalyzer.DatasetAnalyzer_AnalyzeAndConfirm(ds) 

'Ready to use your dataset now' 
Return ds 

다음은 전체 클래스입니다.

Public Class DatasetAnalyzer 

#Region " DatasetAnalyzer " 

    'Run this before loading tables in your dataset, if you plan to call DatasetAnalyzer_GetMissingParentRows. 
    'Must call DatasetAnalyzer_AnalyzeAndConfirm when done creating dataset to re-enable relations. 
#Region " DatasetAnalyzer_Init " 
    Public Shared Sub DatasetAnalyzer_Init(ByVal ds As Data.DataSet) 
     ds.EnforceConstraints = False 

     ds.BeginInit() 
     For Each dt As Data.DataTable In ds.Tables 
      dt.BeginInit() 
      dt.BeginLoadData() 

     Next 

    End Sub 
#End Region 

    'Checks for dataset constraint errors and gives detailed error messages if any are found. 
    'Assumes DatasetAnalyzer_Init is called on that dataset 
#Region " DatasetAnalyzer_AnalyzeAndConfirm " 
    Public Shared Sub DatasetAnalyzer_AnalyzeAndConfirm(ByVal ds As Data.DataSet) 
     DatasetAnalyzer_EnsureInitialization(ds) 

     Try 
      For Each dt As Data.DataTable In ds.Tables 
       dt.EndLoadData() 
       dt.EndInit() 
      Next 
      ds.EndInit() 

      ds.EnforceConstraints = True 

     Catch ex As Data.ConstraintException 
      'We've found a constraint exception...figure out what it is 

      Dim sErrorMessage As String = "DatasetAnalyzer_AnalyzeAndConfirm : " 

      For Each oTbl As Data.DataTable In ds.Tables 
       If oTbl.HasErrors Then 

        'Report the first error only 
        Dim oRow As Data.DataRow = oTbl.GetErrors(0) 
        sErrorMessage &= oTbl.TableName & " : " & oRow.RowError & " : " 

        'Detail for Foreign Key Violations 
        If oTbl.ParentRelations IsNot Nothing Then 
         For Each oRel As Data.DataRelation In oTbl.ParentRelations 
          If oRel.ChildKeyConstraint IsNot Nothing AndAlso oRow.GetParentRow(oRel) Is Nothing Then 
           'a parent constraint for this relation exists and the data that is constrained is non-existant. If this isn't a null value then we found a problem 
           For Each o As Data.DataColumn In oRel.ChildColumns 
            If Not oRow.IsNull(o) Then 
             'We have a confirmed foreign key violation...generate a pretty message 

             Dim ParentColumnNames(oRel.ParentColumns.Length - 1) As String 
             Dim ChildColumnNames(oRel.ChildColumns.Length - 1) As String 


             For i As Int32 = 0 To ParentColumnNames.Length - 1 
              ParentColumnNames(i) = oRel.ParentColumns(i).ColumnName 
             Next 

             For i As Int32 = 0 To ChildColumnNames.Length - 1 
              ChildColumnNames(i) = oRel.ChildColumns(i).ColumnName 
             Next 

             sErrorMessage &= "ParentTable = " & oRel.ParentTable.TableName & " (" & String.Join(", ", ParentColumnNames) & "), " 
             sErrorMessage &= "ChildTable = " & oRel.ChildTable.TableName & " (" & String.Join(", ", ChildColumnNames) & "), " 

            End If 
           Next 
          End If 
         Next 
        End If 


        'Additional Column info that might be usefull 
        If oRow.RowError.Contains("MaxLength") Then 
         For Each oCol As Data.DataColumn In oRow.GetColumnsInError 
          sErrorMessage &= oCol.ColumnName & ".MaxLength = " & oCol.MaxLength 
         Next 
        End If 


        'Report the error with details about the row that errored 
        sErrorMessage &= Environment.NewLine & Environment.NewLine & "Debug Data = " & DatasetAnalyzer_GetRowDebugData(oRow) 
        Throw New Exception(sErrorMessage) 

       End If 
      Next 


      Throw New Exception("Dear Developer, Unknown Constraint Exeption", ex) 
     End Try 

    End Sub 
#End Region 

    'Returns an array of detached rows that are "missing" in the ParentTable. 
    'Returns an empty array if no values exist 
#Region " DatasetAnalyzer_GetMissingParentRows " 
    Public Shared Function DatasetAnalyzer_GetMissingParentRows(ByVal ParentTable As Data.DataTable) As Data.DataRow() 
     If ParentTable.DataSet Is Nothing Then 
      Throw New Exception("Dear Developer, DatasetAnalyzer_GetMissingParentRows : ParentTable must belong to a dataset. Table = " & ParentTable.TableName) 
     End If 

     DatasetAnalyzer_EnsureInitialization(ParentTable.DataSet) 

     Dim drMissingParents As New Collections.Generic.List(Of Data.DataRow) 

     Try 
      'Turn on the constraints to see if anything breaks 
      ParentTable.DataSet.EnforceConstraints = True 

     Catch ex As Data.ConstraintException 

      For Each oRel As Data.DataRelation In ParentTable.ChildRelations 
       If oRel.ChildKeyConstraint IsNot Nothing AndAlso oRel.ChildTable.HasErrors Then 
        'This relationship has a child key constraint...this child table has errors 

        For Each oRow As Data.DataRow In oRel.ChildTable.GetErrors 
         If oRow.GetParentRow(oRel) Is Nothing Then 
          ' This foreign key that is constrained is non-existant. If this isn't a null value then we found a problem 
          For Each o As Data.DataColumn In oRel.ChildColumns 
           If Not oRow.IsNull(o) Then 
            ' non-null missing foreign key constraint 
            Dim drMissingParent As Data.DataRow = ParentTable.NewRow 

            ' Create the proposed parent record by matching the child record 
            For i As Int32 = 0 To oRel.ParentColumns.Length - 1 
             drMissingParent(oRel.ParentColumns(i)) = oRow(oRel.ChildColumns(i)) 
            Next 

            'Search for a duplicate Missing Parent...only need to report each one once 
            Dim bFoundDupe As Boolean = False 
            For Each dr As Data.DataRow In drMissingParents 
             bFoundDupe = True 

             For i As Int32 = 0 To ParentTable.Columns.Count - 1 
              If Not dr(i).Equals(drMissingParent(i)) Then 
               bFoundDupe = False 
               Exit For 
              End If 
             Next 

             If bFoundDupe Then Exit For 
            Next 

            If Not bFoundDupe Then 
             drMissingParents.Add(drMissingParent) 
            End If 

            Exit For 'Checking for non-nulls Columns 
           End If 
          Next 
         End If 
        Next 
       End If 
      Next 
     End Try 

     ParentTable.DataSet.EnforceConstraints = False 

     Return drMissingParents.ToArray 
    End Function 
#End Region 

    'Returns the string representation of row data 
#Region " DatasetAnalyzer Private Support Methods " 

    Private Shared Function DatasetAnalyzer_GetRowDebugData(ByVal oRow As Data.DataRow) As String 
     Dim Values(oRow.Table.Columns.Count - 1) As String 


     For Each oCol As Data.DataColumn In oRow.Table.Columns 
      Dim Value As String 
      If oRow.IsNull(oCol) Then 
       Value = "<NULL>" 
      Else 
       Value = oRow(oCol).ToString 
      End If 

      Values(oCol.Ordinal) = oCol.ColumnName & ":" & Value 
     Next 


     Return String.Join(", ", Values) 
    End Function 

    Private Shared Sub DatasetAnalyzer_EnsureInitialization(ByVal ds As Data.DataSet) 
     If ds Is Nothing Then 
      Throw New Exception("Dear Developer, Must construct the ds object before calling InDatasetAnalyzer_Init (ds = New ...)") 
     End If 

     If ds.EnforceConstraints Then 
      Throw New Exception("Dear Developer, call DatasetAnalyzer_Init before calling DatasetAnalyzer_AnalyzeAndConfirm") 
     End If 
    End Sub 
#End Region 
#End Region 

End Class 

이제 유용한 정보로 문제를 해결할 수 있습니다.

관련 문제