使用Oracle Managed Driver Core的asp.net core docker容器.打开连接时抛出ORA-00604和ORA-01882 [英] asp.net core docker container using Oracle Managed Driver Core. throws ORA-00604 and ORA-01882 when opening connection
问题描述
当尝试使用针对dotnet core的Oracle Managed Data Access连接到oracle数据库时,我收到以下异常( https://www.nuget.org/packages/Oracle.ManagedDataAccess.Core/)从Docker容器内部进行.我没有在docker
之外收到异常复制步骤:
- 打开VS 2017
- 文件>新建>项目...
- Visual C#> .Net Core> ASP.Net Core Web应用程序
- 点击确定
- 选择"Web应用程序(模型-视图-控制器)"
- 取消选中已启用Docker支持"
- 取消选中配置HTTPS"
- 点击确定
- 在程序包管理器控制台中,执行
Install-Package Oracle.ManagedDataAccess.Core -Source nuget.org -Version 2.18.3
- 将代码粘贴到HomeController.Index方法中
- 在行
con.Open();
上设置断点
- 点击调试IIS Express"按钮
- 尝试打开连接时不会引发异常.
- 停止调试
- 在解决方案资源管理器中右键单击Web项目>添加> Docker支持
- 选择"Linux"单选按钮,然后单击确定"
- 右键单击解决方案资源管理器"中的Web项目>添加">"Container Orchestrator支持"
- 在下拉菜单中选择"Docker Compose",然后单击确定"(取决于所安装的Visual Studio 2017的版本,这可能会有所不同)
- 如果显示任何弹出窗口要求覆盖文件,请单击是".
- 单击调试""Docker Compose"按钮
- 尝试打开连接时将引发异常
代码:
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答案进行了一些其他测试,发现了一些有趣的东西.如果我回滚到版本 2.12.0-beta3 ODP.Net核心( https://www.nuget.org/packages/Oracle. ManagedDataAccess.Core ),并删除了TZ = America/Denver环境变量,我可以正确打开连接.似乎已将某些内容引入 2.18.3 中,在docker容器内打开连接时对TZ环境变量的要求.
我只是在类似的环境(Oracle DB 11.2.0.4.0和NuGet包Oracle.ManagedDataAccess.Core 2.18.3)中找到了该解决方案:>
在容器中添加一个名为TZ
的环境变量,并将其值设置为您的时区,例如CET
这使我可以打开连接.然后,我还可以使用此解决方案中的部分来设置会话信息
this.Connection = new OracleConnection();
this.Connection.ConnectionString = ...
this.Connection.Open();
OracleGlobalization info = this.Connection.GetSessionInfo();
info.TimeZone = "America/New_York";
this.Connection.SetSessionInfo(info);
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:\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()
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.
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);
这篇关于使用Oracle Managed Driver Core的asp.net core docker容器.打开连接时抛出ORA-00604和ORA-01882的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!