Connect to Oracle Autonomous db using PowerShell in Linux

1

I have an autonomous Oracle DB set up in the cloud and can access this successfully via a number of different routes, SQL developer (Linux), PowerShell (Linux) and cx_python(Linux) for reasons best known to myself I wanted to see if I could use PowerShell on Linux in VS Code to connect to the same database.

I have

  • downloaded the wallet and placed it in the directory /home/simon/Documents/Wallet_DB202006252115.
  • Oracle.ManagedDataAccess.Core.2.19.101 installed
  • Microsoft.NETCore.App 5.0.2 installed.

The base PowerShell (PowerShell Integrated Console v2020.6.0) code I am running from VS Code is

$connectionstring = 'User Id=' + $username + ';Connection Timeout=120 ;Password=' + $password + ';Data Source=' + $datasource
$con = New-Object Oracle.ManagedDataAccess.Client.OracleConnection($connectionstring)
$con.TnsAdmin='/home/simon/Documents/Wallet_DB202006252115'
$con.WalletLocation='/home/simon/Downloads/Wallet_DB202006252115'
$con.Open()

with user id etc.. set appropriately. It is reading the TNS data correctly as if I change the source name it gives a TNS error. The DLL has been loaded successfully as I can access connection object.

With this set up I get the following errors

Automation.MethodInvocationException: Exception calling "Open" with "0" argument(s): "ORA-00542: Failure during SSL handshake"
 ---> Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> OracleInternal.Network.NetworkException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
 ---> Interop+Crypto+OpenSslCryptographicException: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
   --- End of inner exception stack trace ---

Any suggestions..

Thanks

Edit - added trace


021-01-28 20:00:29.127597 TID:1   (CFG) (ENV)      Machine Name : simon-IOTA2320
2021-01-28 20:00:29.129182 TID:1   (CFG) (ENV)      User Name : simon
2021-01-28 20:00:29.129700 TID:1   (CFG) (ENV)      OS Version : Unix 5.8.0.40
2021-01-28 20:00:29.129817 TID:1   (CFG) (ENV)      64-bit OS : True
2021-01-28 20:00:29.129877 TID:1   (CFG) (ENV)      64-bit Process : True
2021-01-28 20:00:29.130483 TID:1   (CFG) (ENV)      .NET Core Runtime Version : 5.0.2
2021-01-28 20:00:29.130558 TID:1   (CFG) (ENV)      Application Directory : /home/simon/Documents/test/bin/Debug/net5.0
2021-01-28 20:00:29.130583 TID:1   (CFG) (VER)      Oracle Data Provider for .NET Core Driver Version : 2.0.19.1
2021-01-28 20:00:29.153996 TID:1   (CFG) (VER)      Oracle Data Provider for .NET Core Driver Informational Version : 2.0.19.1:20201224
2021-01-28 20:00:29.154283 TID:1   (CFG) (.NET)     SSL_SERVER_DN_MATCH : yes
2021-01-28 20:00:29.154342 TID:1   (CFG) (.NET)     WALLET_LOCATION : /home/simon/Documents/Wallet_DB202006252115
2021-01-28 20:00:29.162967 TID:1   (CFG) (SQLNET)   FilePath : (null)
2021-01-28 20:00:29.163089 TID:1   (CFG) (TNSNAMES) FilePath : /home/simon/Documents/Wallet_DB202006252115/tnsnames.ora
2021-01-28 20:00:29.186669 TID:1   (CFG) (OCFG)     OracleConfiguration.TraceFileLocation() : /home/simon/Documents/PowerShell
2021-01-28 20:00:29.187092 TID:1   (CFG) (OCFG)     OracleConfiguration.TraceLevel() : 7
2021-01-28 20:00:29.187308 TID:1   (CFG) (OCFG)     OracleConfiguration.CommandTimeout() : 120
2021-01-28 20:00:29.187354 TID:1   (CFG) (OCFG)     OracleConfiguration.TnsAdmin() : /home/simon/Documents/Wallet_DB202006252115
2021-01-28 20:00:29.187385 TID:1   (CFG) (OCFG)     OracleConfiguration.WalletLocation() : /home/simon/Documents/Wallet_DB202006252115
2021-01-28 20:00:29.114716 TID:1   (PUB) (ENT) OracleConnection.Open() (conid=27252167) (state=Closed) (sessid=0) (implid=0) (pooling=T) (txnid=n/a) 
2021-01-28 20:00:29.192468 TID:1   (PRI) (ENT) (CP) OracleConnectionDispenser..cctor()
2021-01-28 20:00:29.193968 TID:1   (PRI) (EXT) (CP) OracleConnectionDispenser..cctor()
2021-01-28 20:00:29.194179 TID:1   (PRI) (ENT) (CP) OracleConnectionDispenser.Get()
2021-01-28 20:00:29.198567 TID:1   (PRI) (ENT) (CP) PoolManager.ctor()
2021-01-28 20:00:29.201716 TID:1   (PRI) (EXT) (CP) PoolManager.ctor()
2021-01-28 20:00:29.205059 TID:1   (PRI) (ENT) (CP) PoolManager.Initialize() (constr=User Id=AOracleDMIN;Data Source=db202006252115_high;Connection Timeout=120;)
2021-01-28 20:00:29.206900 TID:1   (PRI) (EXT) (CP) PoolManager.Initialize() (pmid=43942917) (constr=User Id=AOracleDMIN;Data Source=db202006252115_high;Connection Timeout=120;)
2021-01-28 20:00:29.209809 TID:1   (PRI) (BUF) (OBP.CTOR) (poolid:59941933) (OracleConnectionDispenser`3.GetPM)
2021-01-28 20:00:29.217997 TID:1   (PRI) (ENT) (CP) OraclePoolManager.Get()
2021-01-28 20:00:29.282032 TID:1   (PRI) (ENT) (CP) PoolManager.Get() (txnid=n/a) (bForceMatch=F)
2021-01-28 20:00:29.282979 TID:1   (PRI) (ENT) (CP) PoolManager.Get() MultiTenant : Searching for a idle connection, retryCountWithoutAffinity: 0
2021-01-28 20:00:29.284439 TID:1   (PRI) (ENT) PoolManager.ProcessCriteriaCtx_NonEnlistedConnection()
2021-01-28 20:00:29.284565 TID:1   (PRI) (EXT) PoolManager.ProcessCriteriaCtx_NonEnlistedConnection()
2021-01-28 20:00:29.300606 TID:1   (PRI) (ENT) (CP) PoolManager.CreateNewPR() (txnid=n/a) 
2021-01-28 20:00:29.310788 TID:4   (PRI) (ENT) (CP) PoolManager.CreateNewPRThreadFunc()
2021-01-28 20:00:29.310916 TID:4   (PRI) (ENT) (CP) PoolManager.CreateNewPRThreadFunc() (initiated by TID:1)
2021-01-28 20:00:29.325121 TID:4   (PRI) (SVC) (ENT) OracleConnectionImpl.Connect() (oper=open) (aff=n/a) (inst=) (affmatch=n/a) (pr.service=) (pr.pdb=) (pr.edition=) (sessid=-1:-1) (F;F;F;;N) (pmid=43942917) 
2021-01-28 20:00:29.327817 TID:4   (PRI) (BUF) (COBP.CTOR) (poolid:1) (parentpoolid:59941933) (OracleConnectionImpl.Connect)
2021-01-28 20:00:29.462051 TID:4   (NET) (ENT) TcpsTransportAdapter.Connect()
2021-01-28 20:00:29.463189 TID:4   (NET) (ENT) TcpTransportAdapter.Connect()
2021-01-28 20:00:29.464190 TID:4   (NET)      Trying (host=138.1.83.12) (port=1522)
2021-01-28 20:00:29.464300 TID:4   (NET) (EXT) TcpTransportAdapter.Connect()
2021-01-28 20:00:29.464365 TID:4   (NET) (EXT) TcpsTransportAdapter.Connect()
2021-01-28 20:00:29.466303 TID:4   (NET) (ENT) TcpsTransportAdapter.ConnectIterate()
2021-01-28 20:00:29.469401 TID:4   (NET) (ENT) TcpTransportAdapter.ConnectIterate()
2021-01-28 20:00:29.478126 TID:4   (NET)      Trying (address=138.1.83.12) (port=1522)
2021-01-28 20:00:29.526221 TID:4   (NET) (ENT) TcpsTransportAdapter.Negotiate()
2021-01-28 20:00:29.526768 TID:4   (NET) (SQLNET) SSLVersion = 0. SSLProtocol = Tls, Tls11, Tls12.
2021-01-28 20:00:29.527414 TID:4   (NET) (SQLNET) MY_WALLET_DIRECTORY = /home/simon/Documents/Wallet_DB202006252115
2021-01-28 20:00:29.963897 TID:4   (NET) (ENT) TcpsTransportAdapter.ConnectIterate()
2021-01-28 20:00:29.964789 TID:4   (NET) (ENT) TcpTransportAdapter.ConnectIterate()
2021-01-28 20:00:29.964896 TID:4   (NET) (EXT) TcpsTransportAdapter.ConnectIterate()
2021-01-28 20:00:29.965961 TID:4   (NET) (ENT) TcpsTransportAdapter.Connect()
2021-01-28 20:00:29.966077 TID:4   (NET) (ENT) TcpTransportAdapter.Connect()
2021-01-28 20:00:29.966109 TID:4   (NET)      Trying (host=147.154.234.37) (port=1522)

The trace continues  like - this trying various ports? until it gives the error shown above.

2021-01-28 20:01:45.183100 TID:1   (PUB) (ERR) OracleConnection.Open() (txnid=n/a) Oracle.ManagedDataAccess.Client.OracleException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> OracleInternal.Network.NetworkException (0x80004005): ORA-00542: Failure during SSL handshake
 ---> System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception.
 ---> Interop+OpenSsl+SslException: SSL Handshake failed with OpenSSL error - SSL_ERROR_SSL.
 ---> Interop+Crypto+OpenSslCryptographicException: error:14094410:SSL routines:ssl3_read_bytes:sslv3 alert handshake failure
   --- End of inner exception stack trace ---
   at Interop.OpenSsl.DoSslHandshake(SafeSslHandle context, ReadOnlySpan`1 input, Byte[]& sendBuf, Int32& sendCount)
   at System.Net.Security.SslStreamPal.HandshakeInternal(SafeFreeCredentials credential, SafeDeleteSslContext& context, ReadOnlySpan`1 inputBuffer, Byte[]& outputBuffer, SslAuthenticationOptions sslAuthenticationOptions)
   --- End of inner exception stack trace ---
   at System.Net.Security.SslStream.ForceAuthenticationAsync[TIOAdapter](TIOAdapter adapter, Boolean receiveFirst, Byte[] reAuthenticationData, Boolean isApm)
   at System.Net.Security.SslStream.ProcessAuthentication(Boolean isAsync, Boolean isApm, CancellationToken cancellationToken)
   at System.Net.Security.SslStream.AuthenticateAsClient(SslClientAuthenticationOptions sslClientAuthenticationOptions)
   at OracleInternal.Network.TcpsTransportAdapter.Negotiate(ConnectionOption conOption)
   at OracleInternal.Network.OracleCommunication.DoConnect(String tnsDescriptor)
   at OracleInternal.Network.OracleCommunication.Connect(String tnsDescriptor, Boolean doNAHandshake, String IName, ConnectionOption CO)
   at OracleInternal.ServiceObjects.OracleConnectionImpl.Connect(ConnectionString cs, Boolean bOpenEndUserSession, OracleConnection connRefForCriteria, String instanceName)
   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()
   --- End of inner exception stack trace ---
oracle
powershell
ubuntu
odp.net
asked on Stack Overflow Jan 22, 2021 by Simon Parkinson • edited Jan 29, 2021 by Simon Parkinson

1 Answer

0

Not particularly obvious from the trace but the issue is caused by the fact I was using the Net Core 5 rather than 3.1, switching to the older run time enables the connection to work.

answered on Stack Overflow Jan 30, 2021 by Simon Parkinson

User contributions licensed under CC BY-SA 3.0