Hi All
I am receiving a 'Violation of UNIQUE KEY constraint'. I atually want the SQL error number.
So i tried to cast the exception to a SQLException - but that gives me 'Specified cast is not valid' then i tried casting the Inner Exception as explained in this message thread - But that returns '<undefined value>'
What else can i try?
Code snippet of first try
public bool Save()
{
try
{
return _Agency_Entity.Save();
}
catch (Exception ex)
{
SqlException sex;
sex = (SqlException)ex; //<--- 'Specified cast is not valid'
//Do something...
}
}
Code snippet of 2nd try
public bool Save()
{
try
{
return _Agency_Entity.Save();
}
catch (Exception ex)
{
SqlException sex;
sex = (SqlException)ex.InnerException; //<--- '<undefined value>'[/color]
//Do something...
}
}
Error Message caught
{"An exception was caught during the execution of an action query: Violation of UNIQUE KEY constraint 'AgencyName'. Cannot insert duplicate key in object 'AgencyRecord'.\r\nThe statement has been terminated.. Check InnerException, QueryExecuted and Parameters of this exception to examine the cause of this exception." }