Link to home
Start Free TrialLog in
Avatar of chokka
chokkaFlag for United States of America

asked on

Failed to enable Constraints - Dataset

Failed to enable constraints. One or more rows contain values violating non-null, unique, or foreign-key constraints.

This Method  executes well  for few Copay Id's and throwing exception for few copayid's.

I am confused, I am sure that, i need to implement Dataset.EnforceConstraint = False - But i really dont know .. where to implement ..!
Public Function GetCoPayToPrint(ByVal CoPayid As Integer) As MedISDataSet.copayreportDataTable
        Dim CoPayPrint As MedISDataSet.copayreportDataTable
        Try
            CoPayPrint = New MedISDataSet.copayreportDataTable
            CoPayPrint.AppRecDateColumn.DateTimeMode = DataSetDateTime.Utc
            CoPayPrint.DOBColumn.DateTimeMode = DataSetDateTime.Utc
            CoPayPrint.LFDColumn.DateTimeMode = DataSetDateTime.Utc
            Dim cmd As New SqlCommand("GetCoPayToPrint", sqlConn)
            cmd.CommandType = CommandType.StoredProcedure
            cmd.Parameters.AddWithValue("@CoPayid", CoPayid)
            Dim da As New SqlDataAdapter(cmd)
            da.Fill(CoPayPrint)
        Catch sqlex As Exception
            EventLogHelper.LogFailureAudit(String.Format("The error was encountered while selecting LFD Data: " & ControlChars.NewLine & "{0}", sqlex.ToString()))
            Throw New SoapException(sqlex.Message, SoapException.ServerFaultCode, "Database")
        Finally
            sqlConn.Close()
        End Try
        Return CoPayPrint
    End Function

Open in new window

Avatar of 13598
13598
Flag of United States of America image

Can't you just do this?
 Try
       MedISDataSet.EnforceConstraints = False    
 CoPayPrint = New MedISDataSet.copayreportDataTable

You don't care to find out what is wrong with the data?
Avatar of chokka

ASKER


Screen Shot of the Error Message
ConstraintException.JPG
Avatar of chokka

ASKER



here is another issue -

 Partial Public Class MedISDataSet
        Inherits Global.System.Data.DataSet

MedISDataset is not a dataset. This is a class which is Inherited from System.Data.Dataset

I am not able to get  MedISDataSet.EnforceConstraint = False
       
Does it always work the very first time it runs?
ASKER CERTIFIED SOLUTION
Avatar of 13598
13598
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of chokka

ASKER



Following code invokes the above the Method ..!
And i am getting another exception from this code.

Also, Dataset is used to load the Crystal Report .
Report file is expecting Dataset  - Username / Password.


Public Shared Function GetCoPayToPrint(ByVal CoPayID As Integer) As MedISDataSet.copayreportDataTable
        ' SyncLock GetType(MedISServices)
        Dim dataService As MedISServices = GetWebServiceReference()
        Dim dataTable As MedISDataSet.copayreportDataTable = Nothing

        Try
            dataTable = dataService.GetCoPayToPrint(CoPayID)
        Catch webEx As WebException
            HandleWebServicesException(WebServicesExceptionType.WebException, webEx)
        Catch soapEx As SoapException
            If soapEx.Actor = "Security" Then
                HandleWebServicesException(WebServicesExceptionType.SoapException, soapEx)
            Else
                HandleWebServicesException(WebServicesExceptionType.WebException, soapEx)
            End If
        Catch ex As Exception
            HandleWebServicesException(WebServicesExceptionType.Exception, ex)
        End Try

        Return dataTable
        'End SyncLock

    End Function

Open in new window

Dataset-UserName-Password.JPG
XMLError.JPG
Avatar of chokka

ASKER


Is there anyway for us to disable or set enforce constraint = false in DataTable.

Since Parent datatable has key

Avatar of chokka

ASKER

Thanks