0

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.

lesderid
  • 3,388
  • 8
  • 39
  • 65
  • Isn't it related with your .Net Framework Language? For ex, If you use Turkish .Net Framework, your exception messages appear as Turkish. Or you can create your own Exception handling like http://www.c-sharpcorner.com/UploadFile/rajeshvs/ExceptionHandlinginCSharp11282005051444AM/ExceptionHandlinginCSharp.aspx – Serkan Hekimoglu Nov 02 '10 at 08:09
  • I'm not sure, the way to 'bypass' the .Net Framework's language (CultureInfo) did not work. – lesderid Nov 02 '10 at 08:15

4 Answers4

2

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

Serkan Hekimoglu
  • 4,234
  • 5
  • 40
  • 64
1

:( 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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
1

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.

Yves M.
  • 3,330
  • 14
  • 12
0

Add Current Language=English to the connection string.

SergeyT
  • 800
  • 8
  • 15