?
Solved

Working on Typed Dataset .xsd - VB.Net

Posted on 2010-01-12
15
Medium Priority
?
1,127 Views
Last Modified: 2013-11-26

I have a Typed Dataset defined in a webservice layer of my Windows Application.  
All data is extracted from Typed Dataset (.xsd).

On random basis, i am getting errors as "Constraint Exception" and "System.Threading.Thread - Failed to enable Constraints."

How to clear the constraint exception error ? Is there any way to clear Typed Dataset on the complete of every  transaction ?

0
Comment
Question by:chokka
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 7
15 Comments
 
LVL 15

Expert Comment

by:x77
ID: 26298826
You can use Dataset.EnforceConstraints = True / False and verify rows in error.

On load each datatable, constraints are disabled for performance. After load are enabled.
You can use a try catch to show rows in error.
You can also use Datarow.GetColumnError and Datarow.GetColumnsInError.

You need resolve each error before EnforceConstraints.

When you create a row - DataTable.NewRow - no constraints applies.
When use DataTable.Rows.Add(TheNewRow), Constraints are validated, if a string Field length exced MaxLength or if field is required and you leave empty, constraint error occurs.
      Try
         ds.EnforceConstraints = True
      Catch ex As Exception
         For Each r In tnd
             If r.HasErrors Then Debug.Print(r(0).ToString)
         Next
         Debug.Print(ex.Message)
      End Try

Open in new window

0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26302684
> Is there any way to clear Typed Dataset on the complete of every  transaction ?
Dateset.Clear() method should do the job. Otherwise, recreate the dataset object.
0
 

Author Comment

by:chokka
ID: 26306101
x77 and CodeCruiser..!

I heartily thank you guys..!

x77
ds.EnforceConstraints = True

codecruiser
Dateset.Clear()

I am using .xsd file. I am confused on implementing.

I am not interested to recreate Typed Dataset.

Already application is too slow.

0
Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26306136
What is the question?
Call the Clear method on the dataset object, whatever its called.
0
 

Author Comment

by:chokka
ID: 26306254

No, it is affecting the data entry in the back end.!

For example, i have a table ..! Members in the Typed Dataset.

here .. we have a column "Status". Status will not allow dbnull

In the constraint exception, i am getting this as error.

On clearing the Dataset.Clear()

it takes long long time to execute the application ..! I am just confused about the performance.


0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26306321
I personally do not like typed datasets. It may be too late but if you can switch to untyped then it would be easier to work with.
0
 

Author Comment

by:chokka
ID: 26318332
CodeCruiser, I do agree with you in the regards of TypedDataset.

but i am working on existing project, so i need to clear constraints.

Dataset.EnforceConstraint is not helpful..! Also Dataset.clear is not working out.

We need to clear constraint - Temporarily will it be possible ..

ds.Enforce = false

and then ds.Enforce = true

Something like this .. will it work out ?
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26321294
Yes the ds.EnforceConstraints = False should work. Did you try it?
0
 

Author Comment

by:chokka
ID: 26323101
ds.EnforceConstraints  = False is working ..

But while on reset to ds.EnforceConstraints = True .. is not workin ..!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26323208
Its because the constraints are violated. EnforceConstraints = True would give error if any of the conditions of the constraint are not met.
0
 

Author Comment

by:chokka
ID: 26326331


Error :

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

Now, What i have to do in this issue.


Try
                    m_dataSet.EnforceConstraints = True
                Catch ex As ConstraintException
                    HandleConstraintException()
                End Try

Open in new window

0
 
LVL 83

Accepted Solution

by:
CodeCruiser earned 2000 total points
ID: 26328555
Just make sure that the data in the table satisfies the constraints. Are you adding data to the datatable?
0
 

Author Comment

by:chokka
ID: 26343083

Codecruiser .., on solving couple of bugs in the past ..with the help of you .. i am so confident that you can help me to fix this simple issue.

It will be great, if you can come on my computer virtually ... !
0
 

Author Closing Comment

by:chokka
ID: 31676305
it works well ..!
0
 
LVL 83

Expert Comment

by:CodeCruiser
ID: 26347498
I would be glad to do that if possible :-)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

777 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