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:
- Open VS 2017
- File > New > Project...
- Visual C# > .Net Core > ASP.Net Core Web Application
- Click Ok
- Select 'Web Application (Model-View-Controller)'
- uncheck 'Enabled Docker Support'
- uncheck 'Configure for HTTPS'
- Click Ok
- In Package Manager Console execute
Install-Package Oracle.ManagedDataAccess.Core -Source nuget.org -Version 2.18.3
- Paste Code into HomeController.Index method
- Set breakpoint on line
con.Open();
- Click Debug "IIS Express" button
- No exception is thrown when trying to open connection.
- Stop debugging
- Right Click on Web Project in Solution Explorer > Add > Docker Support
- Select 'Linux' Radio button and click OK
- Right Click on Web Project in Solution Explorer > Add > Container Orchestrator Support
- In the dropdown select 'Docker Compose' and click OK (depending on the version of Visual Studio 2017 installed this may differ)
- Click Yes if any popups are displayed asking to overwrite files
- Click Debug "Docker Compose" button
- 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:
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 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…