Connecting Tech Pros Worldwide Forums | Help | Site Map

Catch "Cannot insert duplicate key row" exception

Dave
Guest
 
Posts: n/a
#1: Nov 4 '07
I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.

SqlException (0x80131904)

1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?

2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?

I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.

Thanks


Mr. Arnold
Guest
 
Posts: n/a
#2: Nov 4 '07

re: Catch "Cannot insert duplicate key row" exception



"Dave" <Dave.Burkett@Jacobs.comwrote in message
news:1194180379.622626.142620@i13g2000prf.googlegr oups.com...
Quote:
>I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
>
SqlException (0x80131904)
>
1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?
>
2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?
>
I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.
>
You page redirect or ServerTransfer to an error page and display the
message, and you come out of the application gracefully or redirect to a
Logon page as an example.

If you have some kind of problem with inserting records into a SQL Server
table based on a table's primary record-key, you got other problems out the
gate that you should be dealing with, because this kind of error condition
should net be happening if the code is solid.


Dave
Guest
 
Posts: n/a
#3: Nov 4 '07

re: Catch "Cannot insert duplicate key row" exception


Mr. Arnold,
Thanks for the quick reply. I understand what you're saying, and as
far as my code being solid, that's why I'm trying to capturing the
duplicate entry error. Redirecting the page once the specific error
above is caught isn't the issue. The issue is how do I capture the
specific SqlException (0x80131904) error?

Also...

1.) Is an "Cannot insert duplicate key row" exception from a
FormView
returned as part of the ItemInserting or ItemInserted event?

Thanks, and I hope to hear from you soon.





On Nov 4, 7:13 am, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Quote:
"Dave" <Dave.Burk...@Jacobs.comwrote in message
>
news:1194180379.622626.142620@i13g2000prf.googlegr oups.com...
>
>
>
>
>
Quote:
I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
>
Quote:
SqlException (0x80131904)
>
Quote:
1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?
>
Quote:
2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?
>
Quote:
I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.
>
You page redirect or ServerTransfer to an error page and display the
message, and you come out of the application gracefully or redirect to a
Logon page as an example.
>
If you have some kind of problem with inserting records into a SQL Server
table based on a table's primary record-key, you got other problems out the
gate that you should be dealing with, because this kind of error condition
should net be happening if the code is solid.- Hide quoted text -
>
- Show quoted text -

Morten Wennevik [C# MVP]
Guest
 
Posts: n/a
#4: Nov 4 '07

re: Catch "Cannot insert duplicate key row" exception


Hi Dave,

The exception occurs between these events, when the data is attempted inserted in the datagrid's datasource, but if the exception occures, you should be able to see it in the Exception property of the DetailsViewInsertedEventArgs object. This object also has a ExceptionHandled property enabling you to consume the exception.


On Sun, 04 Nov 2007 14:26:07 +0100, Dave <Dave.Burkett@Jacobs.comwrote:
Quote:
Mr. Arnold,
Thanks for the quick reply. I understand what you're saying, and as
far as my code being solid, that's why I'm trying to capturing the
duplicate entry error. Redirecting the page once the specific error
above is caught isn't the issue. The issue is how do I capture the
specific SqlException (0x80131904) error?
>
Also...
>
1.) Is an "Cannot insert duplicate key row" exception from a
FormView
returned as part of the ItemInserting or ItemInserted event?
>
Thanks, and I hope to hear from you soon.
>
>
>
>
>
On Nov 4, 7:13 am, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Quote:
>"Dave" <Dave.Burk...@Jacobs.comwrote in message
>>
>news:1194180379.622626.142620@i13g2000prf.googleg roups.com...
>>
>>
>>
>>
>>
Quote:
>I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
>>
Quote:
SqlException (0x80131904)
>>
Quote:
1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?
>>
Quote:
2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?
>>
Quote:
I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.
>>
>You page redirect or ServerTransfer to an error page and display the
>message, and you come out of the application gracefully or redirect to a
>Logon page as an example.
>>
>If you have some kind of problem with inserting records into a SQL Server
>table based on a table's primary record-key, you got other problems out the
>gate that you should be dealing with, because this kind of error condition
>should net be happening if the code is solid.- Hide quoted text -
>>
>- Show quoted text -
>
>
>


--
Happy coding!
Morten Wennevik [C# MVP]
Mr. Arnold
Guest
 
Posts: n/a
#5: Nov 5 '07

re: Catch "Cannot insert duplicate key row" exception



"Dave" <Dave.Burkett@Jacobs.comwrote in message
news:1194182767.214129.213090@v29g2000prd.googlegr oups.com...
Quote:
Mr. Arnold,
Thanks for the quick reply. I understand what you're saying, and as
far as my code being solid, that's why I'm trying to capturing the
duplicate entry error. Redirecting the page once the specific error
above is caught isn't the issue. The issue is how do I capture the
specific SqlException (0x80131904) error?
>
An Exception I know has Innertext messages you might be able to parce. You
should look at the properties of the Exception.

catch (SqlException sqlex)

sqlex.Innertext or something like that -- look at the Exception properties
to see what you can use to trap on for a specific error.
Quote:
>
1.) Is an "Cannot insert duplicate key row" exception from a
FormView
returned as part of the ItemInserting or ItemInserted event?
I cannot tell you about that one, because I never allow the UI/ASP page to
make direct contact with a database.


Chris Mullins [MVP - C#]
Guest
 
Posts: n/a
#6: Nov 5 '07

re: Catch "Cannot insert duplicate key row" exception


The code to catch this is really pretty easy. The key is to just re-throw it
if it's not the error you're looking for.

try
{
bla bla
}
catch(SqlException ex)
{
if (!ex.ErrorCode == 0x80131904)
throw;

// Put relevant error handling logic here
}

--
Chris Mullins

"Dave" <Dave.Burkett@Jacobs.comwrote in message
news:1194182767.214129.213090@v29g2000prd.googlegr oups.com...
Quote:
Mr. Arnold,
Thanks for the quick reply. I understand what you're saying, and as
far as my code being solid, that's why I'm trying to capturing the
duplicate entry error. Redirecting the page once the specific error
above is caught isn't the issue. The issue is how do I capture the
specific SqlException (0x80131904) error?
>
Also...
>
1.) Is an "Cannot insert duplicate key row" exception from a
FormView
returned as part of the ItemInserting or ItemInserted event?
>
Thanks, and I hope to hear from you soon.
>
>
>
>
>
On Nov 4, 7:13 am, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Quote:
>"Dave" <Dave.Burk...@Jacobs.comwrote in message
>>
>news:1194180379.622626.142620@i13g2000prf.googleg roups.com...
>>
>>
>>
>>
>>
Quote:
>I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
>>
Quote:
SqlException (0x80131904)
>>
Quote:
1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?
>>
Quote:
2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?
>>
Quote:
I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.
>>
>You page redirect or ServerTransfer to an error page and display the
>message, and you come out of the application gracefully or redirect to a
>Logon page as an example.
>>
>If you have some kind of problem with inserting records into a SQL Server
>table based on a table's primary record-key, you got other problems out
>the
>gate that you should be dealing with, because this kind of error
>condition
>should net be happening if the code is solid.- Hide quoted text -
>>
>- Show quoted text -
>
>

Dave
Guest
 
Posts: n/a
#7: Nov 8 '07

re: Catch "Cannot insert duplicate key row" exception


Chirs, Would that be under the Inserted Exception?



On Nov 5, 3:25 pm, "Chris Mullins [MVP - C#]" <cmull...@yahoo.com>
wrote:
Quote:
The code to catch this is really pretty easy. The key is to just re-throw it
if it's not the error you're looking for.
>
try
{
bla bla}
>
catch(SqlException ex)
{
if (!ex.ErrorCode == 0x80131904)
throw;
>
// Put relevant error handling logic here
>
}
>
--
Chris Mullins
>
"Dave" <Dave.Burk...@Jacobs.comwrote in message
>
news:1194182767.214129.213090@v29g2000prd.googlegr oups.com...
>
>
>
Quote:
Mr. Arnold,
Thanks for the quick reply. I understand what you're saying, and as
far as my code being solid, that's why I'm trying to capturing the
duplicate entry error. Redirecting the page once the specific error
above is caught isn't the issue. The issue is how do I capture the
specific SqlException (0x80131904) error?
>
Quote:
Also...
>
Quote:
1.) Is an "Cannot insert duplicate key row" exception from a
FormView
returned as part of the ItemInserting or ItemInserted event?
>
Quote:
Thanks, and I hope to hear from you soon.
>
Quote:
On Nov 4, 7:13 am, "Mr. Arnold" <MR. Arn...@Arnold.comwrote:
Quote:
"Dave" <Dave.Burk...@Jacobs.comwrote in message
>
Quote:
Quote:
>news:1194180379.622626.142620@i13g2000prf.googleg roups.com...
>
Quote:
Quote:
I really don't like the users getting an unhandled expception page,
and I'm still to new with ASP.Net and C#. So please accept my
appology for the 2 part question.
>
Quote:
Quote:
SqlException (0x80131904)
>
Quote:
Quote:
1.) Is an "Cannot insert duplicate key row" exception from a FormView
returned as part of the ItemInserting or ItemInserted event?
>
Quote:
Quote:
2.) What is the recommended way to catch and deal with an "Cannot
insert duplicate key row " exception?
>
Quote:
Quote:
I look at dealing with Exceptions as an Art, and I have a lot of
respect for those that can do it with very little effort. I hope that
one of you will be able to help me with this.
>
Quote:
Quote:
You page redirect or ServerTransfer to an error page and display the
message, and you come out of the application gracefully or redirect to a
Logon page as an example.
>
Quote:
Quote:
If you have some kind of problem with inserting records into a SQL Server
table based on a table's primary record-key, you got other problems out
the
gate that you should be dealing with, because this kind of error
condition
should net be happening if the code is solid.- Hide quoted text -
>
Quote:
Quote:
- Show quoted text -- Hide quoted text -
>
- Show quoted text -

Closed Thread