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

chokkaStudentAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

13598Commented:
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?
0
chokkaStudentAuthor Commented:

Screen Shot of the Error Message
ConstraintException.JPG
0
chokkaStudentAuthor Commented:


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
       
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

13598Commented:
Does it always work the very first time it runs?
0
13598Commented:
If all you want to do is ignore the error just trap it so it doesnt error out and do nothing:

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 cex As ConstraintException
        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
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
chokkaStudentAuthor Commented:


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
0
chokkaStudentAuthor Commented:

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

Since Parent datatable has key

0
chokkaStudentAuthor Commented:
Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.