当我尝试从Docker容器内部使用针对dotnet core(https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/)的Oracle托管数据访问连接到oracle数据库时,收到以下异常。我没有在docker
之外收到异常复制步骤:
Install-Package Oracle.ManagedDataAccess.Core -Source nuget.org -Version 2.18.3
con.Open();
上设置断点代码:
var strm = new Oracle.ManagedDataAccess.Client.OracleConnectionStringBuilder();
strm.UserID = "<username>";
strm.Password = "<password>";
strm.DataSource = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=<db_host>)(PORT = 1521))) (CONNECT_DATA=(SERVICE_NAME=<service_name>)))";
using (var con = new Oracle.ManagedDataAccess.Client.OracleConnection(strm.ConnectionString))
{
con.Open(); // Exception thrown here.
}
例外:
Oracle.ManagedDataAccess.Client.OracleException
HResult=0x80004005
Message=ORA-00604: error occurred at recursive SQL level 1
ORA-01882: timezone region not found
Source=Oracle Data Provider for .NET, Managed Driver
StackTrace:
at OracleInternal.ConnectionPool.PoolManager`3.Get(ConnectionString csWithDiffOrNewPwd, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OraclePoolManager.Get(ConnectionString csWithNewPassword, Boolean bGetForApp, OracleConnection connRefForCriteria, String affinityInstanceName, Boolean bForceMatch)
at OracleInternal.ConnectionPool.OracleConnectionDispenser`3.Get(ConnectionString cs, PM conPM, ConnectionString pmCS, SecureString securedPassword, SecureString securedProxyPassword, OracleConnection connRefForCriteria)
at Oracle.ManagedDataAccess.Client.OracleConnection.Open()
at WebApplication8.Controllers.HomeController.Index() in C:\Users\me\source\repos\WebApplication8\WebApplication8\Controllers\HomeController.cs:line 22
at Microsoft.Extensions.Internal.ObjectMethodExecutor.Execute(Object target, Object[] parameters)
at Microsoft.AspNetCore.Mvc.Internal.ActionMethodExecutor.SyncActionResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker.<InvokeActionMethodAsync>d__12.MoveNext()
我根据下面的@silent答案进行了其他测试,发现了一些有趣的东西。如果我回滚到ODP.Net核心(2.12.0-beta3)的版本https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core,并删除了TZ = America / Denver环境变量,则可以正确打开连接。似乎在2.18.3中引入了一些内容,导致在docker容器内打开连接时导致需要TZ环境变量。
答案 0 :(得分:4)
我只是在类似的环境(Oracle DB 11.2.0.4.0和NuGet包Oracle.ManagedDataAccess.Core 2.18.3)中找到了该解决方案:
在容器中添加一个名为TZ
的环境变量,并将其值设置为您的时区,例如CET
这使我可以打开连接。然后,我还可以使用this解决方案中的部分来设置会话信息
this.Connection = new OracleConnection();
this.Connection.ConnectionString = ...
this.Connection.Open();
OracleGlobalization info = this.Connection.GetSessionInfo();
info.TimeZone = "America/New_York";
this.Connection.SetSessionInfo(info);