Question

using Nhibernate;

I'm trying to insert several values a on table which has an unique index on some columns.

I'd like to know if a particular insert raises an exception for having violated the unique constraint.

So, which particular exception type should i catch? I only want to catch this particular one and let all others go up.

Thanks a lot!

Was it helpful?

OTHER TIPS

I'm afraid that there is no special exception for that. You will have to catch ADO NET exceptions and look on the inner exception text.

IMHO your approach is not the more appropriate. You should query the DB in order to check BEFORE the insert if the data will violate the unique constraint. If it does, then you don't insert the record.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top