Link to home
Start Free TrialLog in
Avatar of Navicerts
NavicertsFlag for United States of America

asked on

SQL Server - displaying PK errors

Hello,

I am writing a ASP.NET page for the user to create some new records for a particular process that happens.  If they attempt to create records for a record set that has already gone through the process the ASP page gives an ugly error message about not being able to see the error message due to security reasons.

I do the same thing on the local server and i get the following primary key violation error message...

"Violation of PRIMARY KEY constraint 'PK_Process'. Cannot insert duplicate key in object 'Process'. The statement has been terminated. "

This is correct, and what i intended the database to do but i would like a nicer looking way to display the error message for the end user.

Thanks!

-Navicerts
SOLUTION
Avatar of strickdd
strickdd
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 Navicerts

ASKER

The only way i could prevent the error from happening is to change the text box variables to drop down list variables, only displaying the avalible ones.  The drop down list and actually get a bit long so i was going with the text box's.

With custom errors, it will still go to a seprate page where the user is going to have to hit "back" and try to submit again.  this is a bit ugly.  Perhaps i can handle this by putting the SQL statements in a stored proceedure and making some type of "If" statement?

I'll look into the options you wrote here though, thank you so far.

-Navicerts
SOLUTION
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
SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland 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
ASKER CERTIFIED SOLUTION
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
Ok, i have written custom validators before but none that evaluate info returned from a query, just ones that validate date's to make sure they are dates, text box's to make sure they are filled in, excetra.  I'll give this a shot and post back.  Thank You.

-Navicerts
SOLUTION
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
Just an update, I am changing the page to accept values from drop down lists instead of text box's.  If i narrow down the avalible choices based off current date the list in the drop down menu goes to a managable size.  This is my first time making a page in Visual Studio .NET as opposed to ASP Matrix so evreything is a bit of a challenge.

After i get the drop down lists working ill work on that validation control and get back to you guys.  Thanks again for your help.

-Navicerts
Once i had pull down's instead of text box's i was able to narrow down the record set so that it should be impossible to select something that will not work throught my stored proceedures.  I guess im all set with custom validation controls that pass a value for now, did it through SQL.

Thanks all for the help.

-Navicerts