none
How to change the language of returned exceptions? RRS feed

  • Question

  • I have a asp.net app which connects to a sql server database. db server is installed on an English windows box.  Returned exceptions are in English. I hope the exception messages are displayed in the language of the client browser. How to achieve it? Thanks.

    E.g., client may get below error:

    Cannot insert the value NULL into column 'emp_name', table 'Student.dbo.Employee';

    column does not allow nulls. INSERT fails.

    The statement has been terminated.

    What is the simpliest method to get above message in Chinese? I hope it this can be achieved ootb, without local handling.




    • Edited by Leon Zeng Friday, March 20, 2015 1:43 PM
    • Moved by Bob Beauchemin Friday, March 20, 2015 4:35 PM Moved to the forum for client-side SqlClient for best results
    Friday, March 20, 2015 1:09 PM

Answers

  • Hello Leon,

    SQL Server returns the exception in the current session language, which is by default the default language of the used login; but you can change the session language on any time; example

    SET LANGUAGE ENGLISH;
    SELECT 1/0;
    GO
    
    SET LANGUAGE DEUTSCH;
    SELECT 1/0;
    GO

    Result:


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by Leon Zeng Friday, March 20, 2015 1:44 PM
    Friday, March 20, 2015 1:41 PM

All replies

  • There are ways to convert the language your web page is displayed in, but you are trying to convert a static message to a different language. That will likely require you to run the exception message through a language converter. If the exceptions are standard windows exceptions (or similar, meaning they are defined in a library somewhere) there is a chance that you could just use the exception code/number and embed the dll or mui containing the exception messages (for each language) into your asp page and have the page display the message using the appropriate dll file for the language of the endpoint. Just lookup the message by error code. That should remain consistent throughout all language packs.

    If the server that throws the exceptions has multiple language packs installed there is a good chance you will have the libraries you need already in place. I would start by looking under the language specific folders in the %windir%\system32 folder.



    • Edited by mdkelley Friday, March 20, 2015 1:35 PM
    Friday, March 20, 2015 1:20 PM
  • Since sql server support multiple languages, it should be able to return eroor messages in, e.g., Chinese. 
    Friday, March 20, 2015 1:24 PM
  • Hello Leon,

    SQL Server returns the exception in the current session language, which is by default the default language of the used login; but you can change the session language on any time; example

    SET LANGUAGE ENGLISH;
    SELECT 1/0;
    GO
    
    SET LANGUAGE DEUTSCH;
    SELECT 1/0;
    GO

    Result:


    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    • Marked as answer by Leon Zeng Friday, March 20, 2015 1:44 PM
    Friday, March 20, 2015 1:41 PM
  • Thanks.  This is what I wanted.


    • Edited by Leon Zeng Friday, March 20, 2015 2:53 PM
    Friday, March 20, 2015 1:49 PM
  • I don't know about asp:SqlDataSource if you have the option there to send a simple SQL command against SQL Server; you may ask that in a ASP.NET Forum => http://forums.asp.net/

    Olaf Helper

    [ Blog] [ Xing] [ MVP]

    Friday, March 20, 2015 2:11 PM
  • for asp:SqlDataSource, 

    just add "set language xxx;" before the select/insert/update commands

    Friday, March 20, 2015 3:18 PM