Catching SQL unique key exceptions in .NET

后端 未结 4 2086
自闭症患者
自闭症患者 2020-12-28 21:40

I was wondering if anyone had a more elegant way to check for unique key exceptions from SQL in .NET other than parsing the error message? Right now I am calling the sproc

4条回答
  •  死守一世寂寞
    2020-12-28 22:12

    Parsing error message is bad idea. For example if you are using Ms SQL message can be localized (in different language) and you will not find word that you are looking for.

    If you are using Ms SQL you should check Number property.

提交回复
热议问题