oracle / dotnet-db-samples

.NET code samples for Oracle database developers #OracleDotNet
http://otn.oracle.com/dotnet
MIT License
416 stars 191 forks source link

Oracle TCPS connection #418

Open mihaimyh opened 5 days ago

mihaimyh commented 5 days ago

Hello,

Are there any docs on how to use Oracle.ManagedDataAccess.Core to connect to an Oracle database 19c using TCPs and wallet?

My application connects to multiple databases but one connection needs TCPs.

Best regards, Mihai

alexkeh commented 5 days ago

Here's the ODP.NET TCPS with wallets doc section.

If you're connecting to Oracle Autonomous DB 19c with TCPS and wallet, you can review the .NET and ADB quick start tutorials.

If you're trying to use Easy Connect Plus, you can use something like the following Data Source value: tcps://sales1.us.example.com:1522,sales2.us.example.com;sales3.us.example.com,sales4. us.example.com/MyServiceName?WALLET_LOCATION=/wallets

mihaimyh commented 5 days ago

Hi @alexkeh, thanks for the reply. I am not using Autonomous DB, we have an on-premise database running on Exadata. I still find the docs difficult to follow and implement TCPs connection.

We have tnsnames.ora available at some path on the system where the TCPs connection string is defined. Also ORACLE_HOME and TNS_ADMIN environment variables are defined. sqlnet.ora file is defined and contains the wallet information.

In my application code I am creating an OracleConnectionStringBuilder setting as DataSource the TNS alias, the username and the password and then creating the connection:

        var connectionBuilder = new OracleConnectionStringBuilder
        {
            DataSource = "MDCWD",
            UserID = "some_user",
            Password = "some_password"
        };
        var conn = new OracleConnection(connectionBuilder.ToString());
        await conn.OpenAsync(cancellationToken);

I also tried setting the TnsAdmin & WalletLocation on the OracleConnectionStringBuilder, but it doesn't seems to work.

This is my TNS alias:

MDCWD =
  (DESCRIPTION=
    (ENABLE=BROKEN)
    (CONNECT_TIMEOUT=30)
    (RETRY_COUNT=20)
    (RETRY_DELAY=3)
    (FAILOVER=ON)
    (LOAD_BALANCE=OFF)
   (ADDRESS_LIST=
      (LOAD_BALANCE=ON)
      (ADDRESS=
        (PROTOCOL=TCPS)
        (HOST=oradev.internal-ad)
        (PORT=1521)
      )
    )
    (CONNECT_DATA=
      (SERVICE_NAME=MDCWD)
    )
  )

TNS_ADMIN environment variable is set at:

echo $TNS_ADMIN
/opt/oracle/product/21.3.0/client/network/admin

sqlnet.ora is defined at /opt/oracle/product/21.3.0/client/network/admin/sqlnet.ora:

NAMES.DIRECTORY_PATH= (TNSNAMES, EZCONNECT)

SSL_CIPHER_SUITES = (SSL_RSA_WITH_AES_256_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA)
SSL_CLIENT_AUTHENTICATION = FALSE

WALLET_LOCATION =
  (SOURCE =
    (METHOD = FILE)
      (METHOD_DATA =
      (DIRECTORY = /opt/oracle/product/21.3.0/client/network/admin/ssl)))

SQLNET.ENCRYPTION_TYPES_CLIENT=(AES256)
SQLNET.CRYPTO_CHECKSUM_CLIENT = required
SQLNET.IGNORE_ANO_ENCRYPTION_FOR_TCPS=TRUE

The error I am getting is:

ORA-50201: Oracle Communication: Failed to connect to server or failed to parse connect string

alexkeh commented 5 days ago

ORA-50201 has a lot of possible causes. Debugging a TCPS wallet connection is heavily dependent on client and server configuration, which can be hard to validate without direct system access. Can you turn on ODP.NET tracing and share the trace? If you don't want to publish the trace here, send it to us: dotnet_us(at)oracle.com.

mihaimyh commented 2 days ago

The thing is that using tnsping, it works.

alexkeh commented 2 days ago

ODP.NET Core is a fully managed code driver. It doesn't use the Oracle Client nor C-based code as TNSPING does. One big difference is that the *.ora configuration file search order is different between ODP.NET Core and Oracle Client.