Change NLS_LANGUAGE Oracle Parameter in C#

In this post, I will explain How to change NLS_LANGUAGE Oracle Parameter in your code using C#.

Change NLS_LANGUAGE Oracle Parameter in C#

Set nls_language in toad

I am working on the ASP.NET web application to retrieve data from the oracle database in C#.the data has been retrieved successfully, but suddenly, I had noticed that the format of the retrieving data has been changed, and the web application raises unexpected behavior although I didn’t change anything in my code.

This issue might occur in case, the NLS_LANGUAGE Oracle Parameter has been changed from AMERICAN to ARABIC.

So that I opened the TOAD, and go to Database > Administer > NLS_LANGUAGE Parameter.

Change NLS_LANGUAGE Oracle Parameter

When I set nls_language to AMERICAN, the we application is worked properly,

2

But the NLS_LANGUAGE may be changed again by the database administrator at any time, and this is will raise the issue again! therefore, in the next section, I will try to Change NLS_LANGUAGE Oracle Parameter in code using C#


Change NLS_LANGUAGE Oracle Parameter in C#

Instead of depending on the NLS Parameter setting in Oracle, you should set NLS_LANGUAGE  in the code by doing the following:

Steps

  • Open Visual Studio > Open existing  ASP.NET Solution.
  • Make sure that Oracle.DataAccess.Client reference has been added.
Using Oracle.DataAccess.Client;
  • In your code, specifically, after the connection database open statement,
Oracle.DataAccess.Client.OracleConnection mConnection = new Oracle.DataAccess.Client.OracleConnection(OracleConn);

mConnection.Open();
  • Add the below code.
var si = mConnection.GetSessionInfo();
si.Language = "AMERICAN"; // for English or ARABIC for Arabic
mConnection.SetSessionInfo(si);
  • Build and run your application that should be now working properly.

Conclusion

In this post, we have learned How to set NLS_LANGUAGE Oracle Parameter in your code using C#.

You might also like to read
Have a Question?

If you have any related questions, please don’t hesitate to ask it at deBUG.to Community.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top