Page 1 of 1

Session Parameters

Posted: Fri 28 Jan 2011 11:07
by Dominik
Hi,

We need to establish Session Parameters to Oracle databases for example:

ALTER SESSION SET NLS_COMP=ANSI

ALTER SESSION SET NLS_SORT=SPANISH

How could this be done?

In addition, we need to deal with SQL Server databases, so we need to establish also SET Options like:

SET LANGUAGE SPANISH

Must we need to build a factory pattern in this case or can EF establish Session Parameters or SET Options?

Thanks in advance,

Dominik.

Posted: Fri 28 Jan 2011 16:23
by AndreyR
Take a look at this post, such scenario was already discussed at our forum.
You can use either the ObjectContext.ExecutreStoreCommand or OracleCommand.ExecuteNonQuery to execute these statements.

Posted: Mon 14 Feb 2011 17:10
by Dominik
Thank you very much.

But I must deal with SQL Server databases also, so with this solution I should create a factory or some other solution.

Do you think I could be able to set these vaules using Language keyword in my connection strings? They are different for SQL Server and Oracle...

Thanks again,

Dominik.

Posted: Tue 15 Feb 2011 12:53
by AndreyR
There is a number of approaches, your connection string solution is quite appropriate.

Posted: Tue 15 Feb 2011 13:32
by Dominik
Ok,

At the moment I try to add "Current Language=us_english" to my Sql connection string and it sets the language option at Login.

But how can I set this Session Parameters for Oracle?

ALTER SESSION SET NLS_COMP=ANSI

ALTER SESSION SET NLS_SORT=SPANISH

I don't know what keyword values I must use in the connection string...

Thanks in advance,

Dominik.

Posted: Tue 15 Feb 2011 15:20
by AndreyR
I recommend you to execute the following code in the OnContextCreated method:

Code: Select all

      DbConnection conn = (Connection as EntityConnection).StoreConnection;
      if(conn.GetType().Name == "OracleConnection") {
        conn.Open();
        ExecuteStoreCommand("ALTER SESSION SET NLS_COMP=ANSI");
        ExecuteStoreCommand("ALTER SESSION SET NLS_SORT=SPANISH");
      }
This code guarantees that the same StoreConnection will be used during context lifetime.