In this article, I will explain
How to change “NLS_LANGUAGE” Oracle Parameter via C# in ASP.NET
Scenario
I am working on ASP.NET web application to retrieve a data from oracle database via C# that has been retrieved successfully, Suddenly, I found out 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.
Cause
This issue might occur in case, the NLS_LANGUAGE Oracle Parameter has been changed from AMERICAN to ARABIC.
Solution
Instead of depending on the NLS Parameter setting in Oracle, you should set NLS_LANGUAGE in the code by doing the following:
- 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.