【问题标题】:ORA-00604: error occurred at recursive SQL level 1 ORA-01882: timezone region not foundORA-00604: 递归 SQL 级别 1 发生错误 ORA-01882: 未找到时区
【发布时间】:2020-10-17 06:38:17
【问题描述】:

我正在使用 Oracle.ManagedDataAccess.Core 2.18.6 连接 oracle DB。当我调用 con.Open() 时遇到问题 ORA-00604:递归 SQL 级别 1 发生错误 ORA-01882:找不到时区...Oracle .NET 的数据提供程序,带有 .Net Core 2.2 的托管驱动程序。实施以下解决方案后仍然出现相同的错误。
-我的代码:

DataTable dt = new DataTable();
            Console.WriteLine("Called ");
            
                using (OracleConnection Connection = new OracleConnection(utilityManager.Decrypt(ConnString)))
                {
                    Console.WriteLine("********* Before Connection Open********* ");
                    Connection.Open();

                    Console.WriteLine("********* Connection Open********* ");
                    OracleDataAdapter DataAdapter = new OracleDataAdapter();
                    using (OracleCommand cmd = new OracleCommand(strSQL, Connection))
                    {
                        cmd.BindByName = true;
                        cmd.CommandText = strSQL;
                        cmd.CommandType = CommandType.Text;
                        DataAdapter.SelectCommand = cmd;
                        DataSet ds = new DataSet();
                        DataAdapter.Fill(ds);

                        dt = ds.Tables[0];
                    }
                }
        

我试过的解决方案:

-在docker文件中设置时区如下

ENV TZ=America/New_York
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone

-使用Oracle全球化类

this.Connection = new OracleConnection();
this.Connection.ConnectionString = ...
this.Connection.Open();
OracleGlobalization info = this.Connection.GetSessionInfo();
info.TimeZone = "America/New_York";
this.Connection.SetSessionInfo(info)

-asp.net core docker container using Oracle Managed Driver Core. throws ORA-00604 and ORA-01882 when opening connection

-https://serverfault.com/questions/683605/docker-container-time-timezone-will-not-reflect-changes

【问题讨论】:

  • 对我来说,我可以通过在 Dockerfile 中的 ENTRYPOINT 之后移动 ENV TZ= 片段来解决此问题。由于某种原因,它没有从其他任何地方获取环境变量。

标签: c# oracle docker .net-core dockerfile


【解决方案1】:

当我们尝试将在 Windows 中开发的应用程序部署到 Linux/NGNIX 机器时,我们遇到了同样的问题。虽然代码在 Windows 机器上运行良好,但它抛出了错误“ORA-01882: timezone region not found”。在尝试了几种解决方案后,我们找到了以下解决方案。 在位于 /etc/systemd/system/ 文件夹的 .Net 应用程序的服务文件中,为 Oracle 预期的时区设置环境变量。示例服务文件发布在下面

[Unit]
Description=******

[Service]
WorkingDirectory=/home/****/*****
ExecStart=/home/*****/*****/*****
Restart=always
RestartSec=10 # Restart service after 10 seconds if dotnet service crashes
SyslogIdentifier=offershare-web-app
Environment=ASPNETCORE_ENVIRONMENT=Development
Environment=TZ=Asia/Calcutta

[Install]
WantedBy=multi-user.target

PS:您可以通过运行以下查询来获取 Oracle 时区

SELECT SESSIONTIMEZONE FROM DUAL

【讨论】:

    【解决方案2】:

    对于 ASP.Net Core,您可以将 TZ 添加到您的环境变量并在 Linux 上部署之前进行测试

     "profiles": {
        "IIS Express": {
          "commandName": "IISExpress",
          "launchBrowser": true,
          "launchUrl": "weatherforecast",
          "environmentVariables": {
            "ASPNETCORE_ENVIRONMENT": "Development",
            "TZ" :"Africa/Lagos"
    
          }
        },
    

    【讨论】:

      猜你喜欢
      • 2019-05-01
      • 1970-01-01
      • 1970-01-01
      • 2017-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-06-16
      相关资源
      最近更新 更多