Session Parameters

Discussion of open issues, suggestions and bugs regarding Entity Framework support in ADO.NET Data providers
Post Reply
Dominik
Posts: 29
Joined: Wed 19 May 2010 07:26

Session Parameters

Post by Dominik » Fri 28 Jan 2011 11:07

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Fri 28 Jan 2011 16:23

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.

Dominik
Posts: 29
Joined: Wed 19 May 2010 07:26

Post by Dominik » Mon 14 Feb 2011 17:10

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 15 Feb 2011 12:53

There is a number of approaches, your connection string solution is quite appropriate.

Dominik
Posts: 29
Joined: Wed 19 May 2010 07:26

Post by Dominik » Tue 15 Feb 2011 13:32

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.

AndreyR
Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Tue 15 Feb 2011 15:20

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.

Post Reply