Hello there, I'm trying to catch the exception throwen when I insert a already existing user with the given username into my database. As the title says then I'm using EF. The only exception thats throwen when I try to insert the user into to db is a "UpdateException" - How can I extract this exception to identify whether its a duplicate exception or something else?
+4
A:
catch (UpdateException ex)
{
SqlException innerException = ex.InnerException as SqlException;
if (innerException != null && innerException.Number == ??????)
{
// handle exception here..
}
else
{
throw;
}
}
Put the correct number at ??????
that corresponds to unique constraint violation (I don't know it from the top of my head).
Darin Dimitrov
2010-10-19 09:55:31
amazing, you answered that in the same time i wrote the comment. +1 :)
RPM1984
2010-10-19 09:56:27
Perfect :) - However.. I just tried to catch the ErrorCode and it says that the error code for a duplicate entry is -2146232060 which seems a bit odd to me?
ebb
2010-10-19 10:15:08
My bad.. used errorCode instead. Thanks :)
ebb
2010-10-19 17:29:27