Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.5k views
in Technique[技术] by (71.8m points)

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

I am receiving the below exception when trying to connect to an oracle database using the Oracle Managed Data Access for dotnet core (https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/) from inside a docker container. I do not receive the exception outside of docker

Steps to Reproduce:

  1. Open VS 2017
  2. File > New > Project...
  3. Visual C# > .Net Core > ASP.Net Core Web Application
  4. Click Ok
  5. Select 'Web Application (Model-View-Controller)'
  6. uncheck 'Enabled Docker Support'
  7. uncheck 'Configure for HTTPS'
  8. Click Ok
  9. In Package Manager Console execute Install-Package Oracle.ManagedDataAccess.Core -Source nuget.org -Version 2.18.3
  10. Paste Code into HomeController.Index method
  11. Set breakpoint on line con.Open();
  12. Click Debug "IIS Express" button
  13. No exception is thrown when trying to open connection.
  14. Stop debugging
  15. Right Click on Web Project in Solution Explorer > Add > Docker Support
  16. Select 'Linux' Radio button and click OK
  17. Right Click on Web Project in Solution Explorer > Add > Container Orchestrator Support
  18. In the dropdown select 'Docker Compose' and click OK (depending on the version of Visual Studio 2017 installed this may differ)
  19. Click Yes if any popups are displayed asking to overwrite files
  20. Click Debug "Docker Compose" button
  21. An exception will be thrown when trying to open connection

Code:

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.
}

Exception:

Exception in VS

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:Usersmesource
eposWebApplication8WebApplication8ControllersHomeController.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()

Update:

I was doing some additional testing based on @silent answer below and figured out something interesting. If I rolled back to version 2.12.0-beta3 of the ODP.Net core (https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core) and removed the TZ=America/Denver environment variable I am able to open a connection without error. It looks like something was introduced into 2.18.3 that's causing the requirement for the TZ environment variable when opening a connection inside a docker container.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I just came to the solution in in similar context (Oracle DB 11.2.0.4.0 and NuGet package Oracle.ManagedDataAccess.Core 2.18.3):

Add an environment variable called TZ to your container and set the value to your timezone, e.g. CET

This allowed me to open the connection. Then I can also use the part from this solution to set the session info

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...