lesderid
lesderid

Reputation: 3430

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.

Upvotes: 0

Views: 1265

Answers (4)

SergeyT
SergeyT

Reputation: 850

Add Current Language=English to the connection string.

Upvotes: 1

Serkan Hekimoglu
Serkan Hekimoglu

Reputation: 4284

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

Upvotes: 2

Mazhar Karimi
Mazhar Karimi

Reputation:

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

Upvotes: 1

Yves M.
Yves M.

Reputation: 3318

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.

Upvotes: 1

Related Questions