Catch "Cannot insert duplicate key row" exception | | |
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 | | | | 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. | | | | 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 -
| | | | 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] | | | | 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. | | | | 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 -
>
>
| | | | 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:
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 -
|  | Similar C# / C Sharp bytes | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,449 network members.
|