[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

Failed to enable Constraints  - Dataset

Posted on 2010-03-30
8
Medium Priority
?
420 Views
Last Modified: 2013-11-26
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

0
Comment
Question by:chokka
  • 5
  • 3
8 Comments
 
LVL 16

Expert Comment

by:13598
ID: 29124195
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
 

Author Comment

by:chokka
ID: 29124287

Screen Shot of the Error Message
ConstraintException.JPG
0
 

Author Comment

by:chokka
ID: 29124564


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
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
LVL 16

Expert Comment

by:13598
ID: 29124718
Does it always work the very first time it runs?
0
 
LVL 16

Accepted Solution

by:
13598 earned 2000 total points
ID: 29124982
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
 

Author Comment

by:chokka
ID: 29130079


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
 

Author Comment

by:chokka
ID: 29134054

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

Since Parent datatable has key

0
 

Author Closing Comment

by:chokka
ID: 31709129
Thanks
0

Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Stellar Phoenix SQL Database Repair software easily fixes the suspect mode issue of SQL Server database. It is a simple process to bring the database from suspect mode to normal mode. Check out the video and fix the SQL database suspect mode problem.
Hi, this video explains a free download that you can incorporate into your Access databases, or use stand-alone for contact management. Contacts -- Names, Addresses, Phone Numbers, eMail Addresses, Websites, Lists, Projects, Notes, Attachments…

640 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question