Search code examples
oracleado.netoracle11gconnection-poolingodp.net

How to know if an OracleConnection coming from the connection pool was used before


My application needs to authenticate all session on the DB via a trusted procedure (that sets some values in the session context). Currently this procedure is called for each new session just after it is opened.

I'd now like to improve this by removing unneeded round-trips. Connections from the connection pool which were used (and authenticated) before don't need to call the procedure again because the session context variables are still set on the server.

But I can't find a way to identify reused connections. Is there any way (which of course doesn't need a round-trip too)?

Architecture: Multiple client applications use the same DB account (a read-only account with synonyms to the real schema) to connect. After the connection it is required that each new session calls an authentication procedure to set some session context variables. These context variables are checked on select/insert/update/delete by Oracle FGAC (virtual private database).

My code:

OracleConnection conn = new OracleConnection();
conn.ConnectionString = _connectionString;
conn.Open();

if (true) { // TODO: Identify not yet authenticated connections.
   using (OracleCommand cmd = new OracleCommand("authentication.login", conn)) {
      cmd.CommandType = CommandType.StoredProcedure;
      cmd.Parameters.Add("i_user_id", OracleDbType.Int64).Value = _userId;
      cmd.Parameters.Add("i_role_id", OracleDbType.Int64).Value = _roleId;
      cmd.ExecuteNonQuery();
   }
}

Solution

  • I finally found an answer that clearly states that this isn't possible: ODP.NET connection pooling: How to tell if a connection has been used