0

I follow code example from oracle to configure connection to oracle db using standard connection :

{
  "ConnectionStrings": {
    "DefaultConnection": "User Id=<USER ID>;Password=<PASSWORD>;Data Source=<DATA SOURCE>;"
  }
}

im trying console example to test connection to oracle Autonomous DB :

using System;
using Oracle.ManagedDataAccess.Client;

namespace ODP.NET_Core_Autonomous
{
    class Program
    {
        static void Main(string[] args)
        {
            //Demo: ODP.NET Core application that connects to Oracle Autonomous DB

            //Enter user id and password, such as ADMIN user    
            string conString = "User Id=admin;Password=XXXXXXX;" +

            //Enter net service name for data source value
            "Data Source=autonomous;";

            using (OracleConnection con = new OracleConnection(conString))
            {
                using (OracleCommand cmd = con.CreateCommand())
                {
                    try
                    {
                        //Connect descriptor and net service name entry
                        //Enter the database machine port, hostname/IP, service name, and distinguished name
                        OracleConfiguration.OracleDataSources.Add("autonomous", "(description= (retry_count=20)(retry_delay=3)(address=(protocol=tcps)(port=1522)(host=adb.ap-mumbai-1.oraclecloud.com))(connect_data=(service_name=XXXXXXX_webapi_high.atp.oraclecloud.com))(security=(ssl_server_cert_dn=CN=adb.ap-mumbai-1.oraclecloud.com,OU=Oracle ADB INDIA,O=Oracle Corporation,L=Redwood City,ST=California,C=US)))");

                        //Enter directory where wallet is stored locally
                        OracleConfiguration.WalletLocation = @"/home/opc/wallet/Wallet_webapi.zip";

                        con.Open();

                        Console.WriteLine("Successfully connected to Oracle Autonomous Database");

                        //Retrieve database version info
                        cmd.CommandText = "SELECT BANNER FROM V$VERSION";
                        OracleDataReader reader = cmd.ExecuteReader();
                        reader.Read();
                        Console.WriteLine("Connected to " + reader.GetString(0));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.Message);
                    }

                    Console.ReadLine();
                }
            }
        }
    }
}

result : [opc@myhost oratest]$ sudo dotnet run Connection request timed out

Now i want to test connection to Oracle Cloud (Autonomous DB), how the wallet and connection setting can be configured via appsettings.json ?

1 Answer 1

1

Have a look at here, it has explanation of how to configure your env, then links to sample code.

Sign up to request clarification or add additional context in comments.

5 Comments

- For NuGet installations, unzip the contents into the web application root directory for ASP.NET applications or the .EXE directory for Windows applications. is it applicable for net core (centos 7) ?
The way you use the zip with any application (apart from sqlcl & sqldev) is to unzip it somewhere, modify the included sqlnet.ora directory to make the wallet location point to the directory where you unzipped, and then let your app use this directory (e.g. via TNS_ADMIN env variable). This is applicable tyo Windows, macOs or Linux apps.
finally i got it working, net core TNS_ADMIN cant be set by env variable. it can be set using properties OracleConfiguration.TnsAdmin. OracleConfiguration.TnsAdmin = @"/home/opc/wallet"; // path to extracted wallet. next step to configure it in appsettings.json.
@syahman Hello there... I am currently struggling to connect to oracle myself. I am now failing with the connection string. In which file, part of the webapi should I set OracleConfiguration.TnsAdmin to the path? Could you kindly reproduce this part of the code? Cheers =D
@syahman an also, how can I configure this extracted path that you've mentioned on appsettings.json ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.