The forum will experience an outage sometime between February 10 at 7:00pm EST and February 12 at 11:59 EST for installation of security updates. The actual time and duration of the outage are unknown but attempts will be made to minimize the downtime. We apologize for any inconvenience.

Hello,

I am developing an application that uses the entity framework to access a SQL Anywhere database. The application will be deployed with an OEM version of SA. So I have to authenticate every connection that is opened to have full access to the database (authentication is done sending the "SET TEMPORARY OPTION connection_authentication ..." statement).

How would I tell entity framework to do that for every database connection it is opening?

Greetings and thanks in advance for your answers.

asked 20 Feb '12, 04:24

Andre%20Hentschel's gravatar image

Andre Hentschel
1767715
accept rate: 0%


You can use code like this:

 Assembly lAssembly = Assembly.GetExecutingAssembly();
 System.Data.Metadata.Edm.MetadataWorkspace workspace = new System.Data.Metadata.Edm.MetadataWorkspace(new string[] { "res://*/" }, new Assembly[] { lAssembly });
 iAnywhere.Data.SQLAnywhere.SAConnection myConn=new iAnywhere.Data.SQLAnywhere.SAConnection("dsn=mydatabase");
 // here you can issue the Set Temporary Option command on the just created connection
 // and now provide the connection to your entities:

 Entities lEntities = new Entities(new EntityConnection(workspace, myConn));
permanent link

answered 20 Feb '12, 05:37

Martin's gravatar image

Martin
8.6k114149237
accept rate: 14%

Hi and thanks for the quick response. I assume this example is for using ObjectContext (EF 4.0)? DbContext (EF 4.1) has different CTor overloads (it doesn't take an EntityConnection but a DbConnection, so maybe I could put the SAConnection directly into the DbContext).

But the real question here is: Will the externally created SAConnection be used for the whole lifetime of the ObjectContext/DbContext? As far as I know DbConnections are opened and closed on demand in the context for each query/command that is issued to the database, and the connection authentication has to be done after every Open, right?

(20 Feb '12, 07:09) Andre Hentschel
Replies hidden
Comment Text Removed
1

Yes you can use SAConnection for a DbConnection. For a reopen of a connection you could connect to the DbConnection.StateChange Event to react to the change of state to open. Anyway I doubt, that DBContext will close the connection as it is also said not to dispose the connection which you provide to the constructor.

(20 Feb '12, 09:21) Martin
1

As a different approach, you might also use the InitString SAConnection property or the connection parameter with the same name.

This would be helpful when a framework does create its own connections - cf. the last paragraphs on this doc page.

(20 Feb '12, 09:35) Volker Barth

Thanks a lot for your answers.

(20 Feb '12, 09:56) Andre Hentschel
Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×404
×123
×64
×22

question asked: 20 Feb '12, 04:24

question was seen: 1,590 times

last updated: 20 Feb '12, 09:56