开发者

How to display MSSQL exception messages in a specified language (English) in C#?

How to display MSSQL exception messages in C# in a specified language (开发者_运维技巧English) instead of in the UI language?

I tried changing the thread's CultureInfo but it didn't change anything.


It is not related with CultureInfo, if you want to use different languages in your Exception messages, you need to install .NetFramework Language update. For ex, if you install arabic .net framework, you exception messaages appear like arabic


The message is generated on the SQL Server. How should the Framework do the translation?

What I do is to divide the exceptions in two types:

  • Exception that can be handled and therefore translated into the CurrentUICulture. Keep in mind that the error is most likely very technical and needs to be translated into something the user understands. So a foreign-key exception is not very helpfull even if translated.
  • Exception that can't be handled and that is translated into a general message like 'Sorry for the inconvenience...'

Then for logging the exception into the application log etc. I prefer using the english text. This garanties that most of the developer or system administrators understand what is going on.

For error handling you might take a look at ELMAH.


:( Unfortunately there is no good solution in my mind,

All i can say is to handle each exception in separate catch block.

like:

catch(TimoutException ex) { }

catch(CommunicationException ex) { }

and get appropriate exception message from your global resource.


Add Current Language=English to the connection string.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜