3

I'm creating a C# MVC project that uses Oracle Database. While trying to connect to the DB, I get following error:

ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found.

enter image description here

When I try to connect via SQL developer it works fine. Is there any way that I can solve this problem ?

NOTE: I'm using IIS express for testing

Uwe Keim
  • 39,551
  • 56
  • 175
  • 291
Sandaru
  • 1,229
  • 2
  • 21
  • 39

7 Answers7

5

I was facing the same issue using ODP.NET for .NET Core on Pivotal Cloud Foundry. The core issue is missing timezone information.

Added a timezone by setting "TZ" environment variable for my instance. That fixed the issue for me.

BBC
  • 396
  • 4
  • 12
  • This worked for my team. Added the env var to our container and now we can connect to Oracle, TY! I believe this is the best correct answer for addressing this issue from a .Net program. – Joshua Gunder Sep 26 '19 at 18:29
  • 1
    @JoshuaGunder could you share the `docker statement` to the dockerfile to run it? Thank you – Felipe Oriani Nov 15 '19 at 19:57
2

Actually, this error because of some issue with application Oracle driver which you use and Oracle version of the DB.

NOTE: Please check Both of them and use Updated Oracle versions for your application.

ORA-01882: timezone region not found

Dhananjaya
  • 372
  • 1
  • 6
  • 22
2

Had the same problem in .Net Core 3.1 API with controllers.

had the error on debug, and solved it adding TZ on \Properties\launchSettings.json:

"Docker": {
...
   "environmentVariables": {
        "TZ": "WET"
      }
}
mybrave
  • 1,662
  • 3
  • 20
  • 37
1

This code does not provide an answer but it may help to find your problem. The code is too big for a comment.

Please execute this program. What is the output? Where does it fail?

  static void Main(string[] args)
  {
     Console.WriteLine("OracleGlobalization.TimeZone = {0}", Oracle.DataAccess.Client.OracleGlobalization.GetClientInfo().TimeZone);
     Console.WriteLine(String.Empty);

     Console.WriteLine("TimeZone.CurrentTimeZone.StandardName = {0}", TimeZone.CurrentTimeZone.StandardName);
     Console.WriteLine("TimeZone.CurrentTimeZone.DaylightName = {0}", TimeZone.CurrentTimeZone.DaylightName);
     Console.WriteLine(String.Empty);

     Console.WriteLine("TimeZoneInfo.Local.DisplayName = {0}", TimeZoneInfo.Local.DisplayName);
     Console.WriteLine("TimeZoneInfo.Local.Id = {0}", TimeZoneInfo.Local.Id);
     Console.WriteLine("TimeZoneInfo.Local.StandardName = {0}", TimeZoneInfo.Local.StandardName);
     Console.WriteLine("TimeZoneInfo.Local.DaylightName = {0}", TimeZoneInfo.Local.DaylightName);
     Console.WriteLine(String.Empty);

     var str = new Oracle.DataAccess.Client.OracleConnectionStringBuilder();
     str.UserID = "<username>";
     str.Password = "<password>";
     str.DataSource = "<database name>";
     using ( var con = new Oracle.DataAccess.Client.OracleConnection(str.ConnectionString) ) {
        con.Open();
        Console.WriteLine("Oracle.DataAccess: OracleConnection -> SessionInfo.TimeZone = {0}", con.GetSessionInfo().TimeZone);
        Console.WriteLine("Oracle.DataAccess: Version = {0}", FileVersionInfo.GetVersionInfo(con.GetType().Assembly.Location).FileVersion.ToString());

        var tz = new Oracle.DataAccess.Client.OracleCommand("SELECT SESSIONTIMEZONE FROM dual", con).ExecuteScalar();
        Console.WriteLine("Oracle.DataAccess: SESSIONTIMEZONE = {0}", tz.ToString());
        con.Close();
     }
     Console.WriteLine(String.Empty);

     var strm = new Oracle.ManagedDataAccess.Client.OracleConnectionStringBuilder();
     str.UserID = "<username>";
     str.Password = "<password>";
     str.DataSource = "<database name>";
     using ( var con = new Oracle.ManagedDataAccess.Client.OracleConnection(str.ConnectionString) ) {
        con.Open();
        Console.WriteLine("Oracle.ManagedDataAccess: OracleConnection -> SessionInfo.TimeZone = {0}", con.GetSessionInfo().TimeZone);
        Console.WriteLine("Oracle.ManagedDataAccess: Version = {0}", FileVersionInfo.GetVersionInfo(con.GetType().Assembly.Location).FileVersion.ToString());

        var tz = new Oracle.ManagedDataAccess.Client.OracleCommand("SELECT SESSIONTIMEZONE FROM dual", con).ExecuteScalar();
        Console.WriteLine("Oracle.ManagedDataAccess: SESSIONTIMEZONE = {0}", tz.ToString());
        con.Close();
     }
  }

Update

According to your profile you are based in Sri Lanka. Time zone of Sri Lanka seems to be fairly "volatile", see text from IANA TimeZone Database:

Sri Lanka

From Paul Eggert (2013-02-21): Milne says "Madras mean time use from May 1, 1898. Prior to this Colombo mean time, 5h. 4m. 21.9s. F., was used." But 5:04:21.9 differs considerably from Colombo's meridian 5:19:24, so for now ignore Milne and stick with Shanks and Pottenger.

From Paul Eggert (1996-09-03): "Sri Lanka advances clock by an hour to avoid blackout" (http://www.virtual-pc.com/lankaweb/news/items/240596-2.html, 1996-05-24, no longer available as of 1999-08-17) reported "the country's standard time will be put forward by one hour at midnight Friday (1830 GMT) 'in the light of the present power crisis'."

From Dharmasiri Senanayake, Sri Lanka Media Minister (1996-10-24), as quoted by Shamindra in Daily News - Hot News Section (1996-10-26): With effect from 12.30 a.m. on 26th October 1996 Sri Lanka will be six (06) hours ahead of GMT.

From Jesper Nørgaard Welen (2006-04-14), quoting Sri Lanka News Online http://news.sinhalaya.com/wmview.php?ArtID=11002 (2006-04-13): 0030 hrs on April 15, 2006 (midnight of April 14, 2006 +30 minutes) at present, become 2400 hours of April 14, 2006 (midnight of April 14, 2006).

From Peter Apps and Ranga Sirila of Reuters (2006-04-12) in: http://today.reuters.co.uk/news/newsArticle.aspx?type=scienceNews&storyID=2006-04-12T172228Z_01_COL295762_RTRIDST_0_SCIENCE-SRILANKA-TIME-DC.XML [The Tamil Tigers] never accepted the original 1996 time change and simply kept their clocks set five and a half hours ahead of Greenwich Mean Time (GMT), in line with neighbor India.

From Paul Eggert (2006-04-18): People who live in regions under Tamil control can use [TZ='Asia/Kolkata'], as that zone has agreed with the Tamil areas since our cutoff date of 1970.

From Sadika Sumanapala (2016-10-19): According to http://www.sltime.org (maintained by Measurement Units, Standards & Services Department, Sri Lanka) abbreviation for Sri Lanka standard time is SLST.

From Paul Eggert (2016-10-18): "SLST" seems to be reasonably recent and rarely-used outside time zone nerd sources. I searched Google News and found three uses of it in the International Business Times of India in February and March of this year when discussing cricket match times, but nothing since then (though there has been a lot of cricket) and nothing in other English-language news sources. Our old abbreviation "LKT" is even worse. For now, let's use a numeric abbreviation; we can switch to "SLST" if it catches on.

I assume your database does not recognize your current local time zone of your computer. There might be three possible solutions:

  • Change your computer locale settings to a more stable one, e.g. India
  • Update database with latest version of time zone file, see Upgrading the Time Zone File and Timestamp with Time Zone Data
  • In case you use the ODP.NET Unmanaged driver Oracle.DataAccess.dll (unfortunately you did not tell us) you can set ORA_SDTZ environment variable or Registry key HKEY_LOCAL_MACHINE\SOFTWARE\ORACLE\KEY_<Oracle home name>\ORA_SDTZ / HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\ORACLE\KEY_<Oracle home name>\ORA_SDTZ to desired time zone value. Note, the ODP.NET Managed Driver does not read this Registry values.
Wernfried Domscheit
  • 54,457
  • 9
  • 76
  • 110
1

According to this straight from an Oracle employee, set UseHourOffsetForUnsupportedTimezone property for the Connection to true, before opening it.

con.UseHourOffsetForUnsupportedTimezone = true;
con.Open();

This worked for me as I did not have control on the OracleDB server, and in my crossplatform application, the environment variable usage was not being consistent across linux distros. I had ran Weinfried's snippet on all of them to test and there was no timezone descrepency with OracleDB in my case(both on UTC, no DST) but was still failing on the same plank.

Arindam B
  • 23
  • 5
0

I encountered similar problem few days ago and had to go through multiple answers to arrive at a solution that worked for me.

In summary, this is what I observed: When running your C# application in development/debug mode, you are very likely not to encounter this issue. It's mostly when you deploy to a server in production that this happens.

So this is what I suggest you do:

  1. Find out the time zone of the remote Oracle DB you are trying to connect to. You don't have to physically log into the Db server to do that. Since you can run queries using SQL Developer, run the query below to get the time zone that your deployed environment needs to be in sync with to prevent this error:

SELECT sessiontimezone FROM DUAL;
See sample screenshot of output below: enter image description here
  1. Adjust the time zone (TZ) of your deployment host machine to match that of the OracleDb server.
  • If you are on windows/mac, that may be as easy as going into your datetime settings and adjusting the time zone to match the output of the query in step 1.

  • If your deployment is on a docker container; using docker-compose:

      api.gateway:
        #restart: always
        environment:
          - ASPNETCORE_ENVIRONMENT=Development
          - ASPNETCORE_URLS=http://+:80
          - TZ=Africa/Luanda
  • Running your docker file in command line:

docker run -e TZ=Africa/Luanda debian:jessie date

Hope this provides a bit of details for someone, as it did for me.

Onaefe
  • 306
  • 2
  • 4
-1

According to this and this:

In C:\Program Files\datamodeler 3\datamodeler\bin\datamodeler.conf add

AddVMOption -Duser.timezone="+02:00"
Karthick Raju
  • 757
  • 8
  • 29