How to find out which Oracle Client versions are installed?

If your application uses Oracle database, you will need to install the appropriate version of Oracle Client in your local machine.  As this software keeps being updated, you may find yourself trying to uninstall old versions from your system after a while. The question is that how to find which versions of Oracle Client you have in Windows?

Finding out which Oracle Client you installed it’s not straightforward. You can check PATH variables or run some commands in SQLPLUS or TNSPING. Another approach is using OPatch Utility. In this post, I will talk about a much easier way to Oracle Client versions.

Oracle Client versions

Simply run the query below in the Command Prompt. It will call PowerShell first and search for oraclient*.dll files (Asterisk is used to represent the number such as 10, 11 or 12). Once the query is executed, a nicely formatted table will be displayed with the versions and their paths.

powershell "gci C:\,D:\ -recurse -filter 'oraclient*.dll' -ErrorAction SilentlyContinue | %{ $_.VersionInfo } | ft -Property FileVersion, FileName -AutoSize"
List of Oracle Client versions
List of Oracle Client versions

Make sure to add (or remove) hard disk drives if your system has more or less than 2 drives (C: and D:). In the command, only C: and D: drives are searched.

Alternative Way

You can use the query below in SQL Developer to list the versions of the client libraries used. Please note that this query may list the version which is used by SQL Developer only.

SELECT
  DISTINCT
  s.client_version
FROM
  v$session_connect_info s
WHERE
  s.sid = SYS_CONTEXT('USERENV', 'SID');
List of Oracle Client versions
Query in SQL Developer

Another approach is that querying v$version variable: select * from v$version

References

What is the difference between Ref and Out keywords in C#?

We use ref and out keywords to pass parameters to a method. What exactly the different between these 2 keywords?

Here is an example:

// A simple example for usage of Ref keyword in C#

static void Main(string[] args)
{
    int myVariable = 5;

    string returnText = PrintNumber(ref myVariable);

    Console.WriteLine(returnText);
}

public static string PrintNumber(ref int myVariable)
{
    string returnText = "Result: " + myVariable.ToString();

    return returnText;
}

Output:

You may ask: “Why do we need to use ref or out? Can’t we just pass the parameter without using them?. The answer is “Yes”. However, if you don’t use ref or out, the parameters are sent to methods as values by default. It means, the parameter you pass becomes a new variable in the called method. If you change its value, the variable in the main method won’t change.

In contrast, if you use ref or out keywords,  parameter is passed to the method as reference. It means, it is still the same variable in the main method and called method. If you change the value of this variable, the value of the variable in the main method will change too.

Here is the extended version of our example above:

// Changing the value of the parameter passed by Ref keyword in C#
static void Main(string[] args)
{
    int myVariable = 5;

    Console.WriteLine("Initial value (in the main method): " + myVariable.ToString());

    string returnText = PrintNumber(ref myVariable);

    Console.WriteLine("New value (in the main method): " + returnText.ToString());
}

public static string PrintNumber(ref int myVariable)
{
    Console.WriteLine("Initial value (in the called method): " + myVariable.ToString());

    myVariable++;

    Console.WriteLine("New value (in the called method): " + myVariable.ToString());

    return myVariable.ToString();
}

Output:

Difference between Ref and Out keywords

The main difference is that you have to initialize (or assign a value to) variable in the main method before passing it by ref keyword. However, you don’t have to initialize it in the main method if you are passing it by out parameter.

// The example that shows the difference between ref and out keywords in C#

static void Main(string[] args)
{
    int myVariable = 5;

    string returnText1 = PrintNumber1(ref myVariable);
    string returnText2 = PrintNumber2(out myVariable);

    Console.WriteLine("Passed by ref: " + returnText1.ToString());
    Console.WriteLine("Passed by out: " + returnText2.ToString());

    Console.ReadLine();
}

public static string PrintNumber1(ref int myVariable)
{
    // No initialization here

    return myVariable.ToString();
}

public static string PrintNumber2(out int myVariable)
{
    myVariable = 6; // It must be initialized here

    return myVariable.ToString();
}

Output:

In the called method, if you don’t initialize a parameter passed by out keyword, you will receive the error messages below:

The out parameter ‘myVariable’ must be assigned to before control leaves the current
Use of unassigned out parameter ‘myVariable’

Comparison table

Ref Out
The parameter must be initialized before it is passed a method Parameter doesn’t have to be initialized in the main method
It is not required to initialize (or assign a value to) the parameter in the called method Parameter has to be initialized or a value should be assigned to it in the called method
Ref is useful when the called method needs to modify the passed parameter Out is useful when multiple values need to be returned from a function or method
Data can be passed bi-directionally. It work two-ways Data is passed only one-way (from the called method to the main method)

Notes:

  • Both ref and out keywords are treated the same at compile time but they are treated differently at run time
  • Properties cannot be passed by ref or out keywords

Bonus 1:

Starting from C# 7.0, you can declare variables on the fly while calling a method with out parameter:

int.TryParse("123", out int x);
Console.WriteLine(x);

The code lines above are equivalent to the following lines:

int x;
int.TryParse("123", out x);
Console.WriteLine(x);

Bonus 2:

You don’t have to pass variables/values for every out parameter defined by a method. You can ignore out parameters by simply passing an underscore (_). For example:

TestMethod(out _, out _, out int number, out _)

In the example above, we ignored all out parameters except the third one.

References

How to enable Assembly Binding Logging debugging .NET applications?

If you receive an “Assembly not found” error for your .NET application hosted in IIS, you may feel hopeless for not having much debugging details. IIS doesn’t show the binding trace as this slows down applications. However, there is a way to enable logging.

Example of an assembly/DLL binding issue:

Could not load file or assembly ‘Oracle.DataAccess’ or one of its dependencies. An attempt was made to load a program with an incorrect format.

Solution

Use this quick trick to enable Assembly Binding Logging so that you can see where the binding is failing.

  1. Go to “Start > Run”
  2. Enter “regedit
  3. Go to this key: “HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Fusion”
  4. Change the value of “EnableLog” to “1”. If this key doesn’t exist, create it with DWORD(32-bit) type

Note: Another way of viewing details for failed assembly bindings is to use Microsoft’s Fuslogvw tool. This tool is installed with Visual Studio. Refer to the link below for more details.

Reference: