Search notes:

Set action, client_identifier, client_info and module in v$session with ADO.NET (C#)

The ODP.NET class Oracle.DataAccess.Client.OracleConnection has a few properties whose values, after assigning them, will be shown in some columns of v$session of the session that assigned the values:
Property name Column name
ActionName action
ClientId client_identifier
ClientInfo client_info
ModuleName module
The following simple C# program tries to demonstrate that:
using System;
using System.Data.Common;
using Oracle.DataAccess.Client;
using System.Data;

class Prg {

   private static OracleConnection connectOracle(string user, string password, string dataSource) {
      return new OracleConnection($"user Id={user};password={password};data source={dataSource}");
   }

   static void Main() {

      OracleConnection ora = connectOracle("rene", "rene", "ORA18");
      ora.Open();

      OracleCommand sql = new OracleCommand(@"
        select
           sid,
           serial#,
           osuser,
           username,
           action,
           client_identifier,
           client_info,
           module
        from
           v$session
        where
        --
        -- development/databases/Oracle/installed/dynamic-performance-views/session/identify-own-session
        --
           sid = sys_context('userenv', 'sid')
        ");

      sql.Connection = ora;
   //
   // Values must be set before executing ExecuteReader()
   //
      ora.ActionName = "TQ84: action"     ;
      ora.ClientId   = "TQ84: client id"  ;
      ora.ClientInfo = "TQ84: client info";
      ora.ModuleName = "TQ84: module name";

      OracleDataReader resultSet = sql.ExecuteReader();
      while (resultSet.Read()) {
      //
      // One record/iteration expected only
      //
         for (int colNo=0; colNo<resultSet.FieldCount; colNo++) {

            string colVal;
            if (resultSet.IsDBNull(colNo)) {
               colVal = "<null>";
            }
            else {
               colVal = resultSet[colNo].ToString();
            }
            Console.WriteLine(String.Format("  {0,-20}: {1}",
               resultSet.GetName(colNo),
               colVal
            ));
         }
      }
   }
}
Github repository Oracle-Patterns, path: /Installed/dynamic-performance-views/session/set-action-etc.cs

Compling

I was able to compile the code on the command line (cmd.exe) with the following sequence of commands after setting the necessary environment variable of Visual Studio:
set ORACLE_HOME=c:\oracle\18c
csc -debug -reference:%oracle_home%\ODP.NET\bin\4\Oracle.DataAccess.dll set-action-etc.cs

Executing the program

In order to execute the program, I had to copy the Oracle.DataAccess.dll into the current directory.

See also

dbms_application_info

Index