ClientId problem
ClientId problem
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
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
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
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?
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?
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
-
- Devart Team
- Posts: 1710
- Joined: Thu 03 Dec 2009 10:48
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?
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
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
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:
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[] { });
}
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
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