How to connect to oracle Database from C# Code deployed within docker using wallet file

Patil,B,Basappa 0 Reputation points
2023-08-23T05:08:17.1733333+00:00

Hi All

We are currently working on establishing a connection to an Oracle database from a C# application using the Oracle.DataAccess.Client library. However, we are encountering difficulties when attempting to connect using a wallet file. Our application is an ASP.NET Core MVC application that has been deployed as a Docker image.

If you could provide any documentation, references, or guidance on the correct format for the connection string and how to reference the wallet through Oracle.DataAccess.Client, it would be greatly appreciated. Your assistance in resolving this issue would be invaluable to us.

Developer technologies ASP.NET ASP.NET Core
Developer technologies .NET Other
Developer technologies C#
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Muhammad Binyameen 395 Reputation points
    2023-09-05T17:25:07.21+00:00
    To connect to an Oracle database from a C# application using the Oracle.DataAccess.Client library and a wallet file, you'll need to configure the connection string and reference the wallet correctly. Here's a step-by-step guide:
    
    1. Ensure that the Oracle.DataAccess.Client library is installed in your project. You can do this by adding a reference to the library in your C# project.
    
    2. Make sure that the Oracle Instant Client is installed on the machine where you're running your Docker image. The Instant Client contains the necessary libraries for connecting to Oracle databases.
    
    3. In your ASP.NET Core MVC application, open the appsettings.json file (or create one if it doesn't exist) and add a new entry for the Oracle connection string. The format for the connection string will depend on your specific setup, but here's an example:
    
    ```json
    "ConnectionStrings": {
      "OracleConnection": "Data Source=<database hostname or IP>:<port>/<service name>; User Id=<username>; Password=<password>;"
    }
    

    Replace <database hostname or IP>, <port>, <service name>, <username>, and <password> with the appropriate values for your Oracle database.

    1. Next, you'll need to reference the wallet file in your code. The wallet contains the necessary security credentials to establish a connection. In your C# code, before attempting to connect to the Oracle database, initialize the OracleConfiguration.WalletLocation property to the path of the wallet directory. Here's an example:
    OracleConfiguration.WalletLocation = "<path to the wallet directory>";
    

    Replace <path to the wallet directory> with the actual path to the directory containing your wallet files.

    1. Finally, establish a connection to the Oracle database using the configured connection string. Here's an example of how you can use the Oracle.DataAccess.Client library to connect:
    using (OracleConnection connection = new OracleConnection(configuration.GetConnectionString("OracleConnection")))
    {
        connection.Open();
        // Perform database operations
        connection.Close();
    }
    

    Make sure to replace "OracleConnection" with the name of the connection string key you defined in the appsettings.json file.

    By following these steps, you should be able to establish a connection to the Oracle database from your C# application using a wallet file.

    
    
    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.