Page 1 of 2

ClientId problem

Posted: Mon 28 Jun 2010 14:35
by aldare
Hi,

I've tried to use the new ClientId property of OracleConnection and found out it is closing the connection. The state is Open before I try to set it up and Closed when it's been set.

Is it a bug or am I missing the point of it?

Thank you very much
Ales Lipensky

Posted: Tue 29 Jun 2010 10:42
by StanislavK
The ClientId property can be used to specify the user of the connection. It may be useful, e.g. to distinguish connections of different application instances or different tasks inside a single application instance. The connection should be closed to re-set the ClientId parameter.

Posted: Tue 29 Jun 2010 13:00
by aldare
When I run this code with non-devart OracleConnection object:

using(OracleConnection con = new OracleConnection("..."))
{
con.Open();

Console.WriteLine("Logon time: {0}", new OracleCommand(selectLogon, con).ExecuteScalar());

con.ClientId = System.Security.Principal.WindowsIdentity.GetCurrent().Name;

System.Threading.Thread.Sleep(5000);

Console.WriteLine("Get Client ID: [{0}]", new OracleCommand("SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') FROM DUAL", con).ExecuteScalar());

Console.WriteLine("Logon time: {0}", new OracleCommand(selectLogon, con).ExecuteScalar());

con.Close();
}


I get this output :

Logon time: 29.06.2010 13:54:07
Get Client ID: [KATASTR\zmeskalk]
Logon time: 29.06.2010 13:54:07

Wit that connection it doesn't close it and even doesn't reopen.
Your OracleConnection object is closing it. Why then?

Posted: Wed 30 Jun 2010 12:11
by StanislavK
Thank you for your suggestion, we will investigate the possibility of changing the OracleConnection behaviour on setting the ClientId property. We will inform you about the results.

Posted: Fri 09 Jul 2010 17:54
by StanislavK
The ClientId property is one of the properties used to distribute connections between different connection pools. Thus it is important that ClientId is not changed after the connection is placed to the pool. Could you please specify the scenario in which you need the connection to remain opened when ClientId is changed?

Posted: Mon 12 Jul 2010 15:43
by aldare
I changed the logic so whenever I open the ObjectContext, I set the ClientId of OracleConnection before I send any query to the database.
You can see it here :

OracleConnection connection = entities.GetConnection() as OracleConnection;
if (connection != null)
connection.ClientId = "userABC";

The problem is that when I try to ensure the ClientId has been set ...

var a = entities.ExecuteStoreQuery("SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') FROM DUAL", new object[] { });

I get a null string. Why? I am expecting to receive "userABC"

Thank you

Posted: Tue 13 Jul 2010 08:50
by AndreyR
The problem is the fact that entities.Connection is not an OracleConnection instance. It is an EntityConnection instance.
I have used the following code and have got the correct ClientId value:

Code: Select all

      using (Entities entities = new Entities()) {
        OracleConnection connection = (entities.Connection as EntityConnection).StoreConnection as OracleConnection;
        if (connection != null)
          connection.ClientId = "userABC";
        var a = entities.ExecuteStoreQuery("SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') FROM DUAL", new object[] { });
      }

Posted: Tue 13 Jul 2010 10:23
by aldare
It is a bit more complicated than this. I am using EFProviderWrappers (http://code.msdn.microsoft.com/EFProviderWrappers) and my ObjectContext contains method GetConnection() with that implementation :

public DbConnection GetConnection()
{
return ((DbConnectionWrapper)(this.UnwrapConnection())).WrappedConnection;
}

It actually is returning OracleConnection. I can set the breakpoint and it goes to the if(...) section and sets the ClientId correctly.

Anyway, I've tried it without the EFProviderWrappers and the result is the same - null value.

I can send you a printscreen with exactly your code and values in watch showing correctly set ClientId of OracleConnection and null value int the result of calling SELECT SYS_CONTEXT('USERENV','CLIENT_IDENTIFIER') FROM DUAL

I am a bit confused why it should work at your systems and not mine.

Thank you for any suggestions

Posted: Wed 14 Jul 2010 10:30
by AndreyR
Could you please make a simple test project for this error reproducing?
Maybe the error is associated with the EFProvider Wrapper.
One more thing: maybe the query results simply were not materialized, try calling First() after the query.

Posted: Wed 14 Jul 2010 14:49
by aldare
Of course, I can. Where can I post it?

btw: The error is there even without the wrappers. And it has been materialized.

Posted: Thu 15 Jul 2010 10:23
by AndreyR
As far as I understood, the problem is reproducible using the code I have posted.
Are you using the latest 5.70.146 build of dotConnect for Oracle?
What are your Oracle server and client versions?

Posted: Thu 15 Jul 2010 11:30
by aldare
Yes, it is reproducible. So probably it doesn't make sense to send it to you.
I am using 5.70.146.
Oracle server is 11.2g
I am not using any client, just direct access. Might that be the reason?

Thank you

Posted: Thu 15 Jul 2010 12:19
by AndreyR
Thank you for the additional information.
I have reproduced the problem with the Direct mode.
I will post here about the results of our investigation.

Posted: Thu 15 Jul 2010 12:59
by aldare
It is not critical for us, I've used the client and it works.
Thank you

Posted: Thu 03 Mar 2011 14:08
by Shalex
We have fixed the bug with the OracleConnection.ClientId property in the Direct mode. I will post here when the new build of dotConnect for Oracle is available for download.