Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Working on Typed Dataset .xsd - VB.Net

Posted on 2010-01-12
15
Medium Priority
?
1,145 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
  • 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure Cloud.

 
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

Technology Partners: 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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
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…
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an anti-spam), the admin…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Suggested Courses
Course of the Month13 days, 14 hours left to enroll

581 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