Change oracle connection dynamically for EntityFramewok

Change oracle connection dynamically for EntityFramewok

Postby susane_li@yahoo.com » Fri 20 Aug 2010 15:58

Hi, I'm working in WPF and trying to create Entity Data Model based on DotConnect to Oracle, it works well if the connectionstring is fixed and specified in app.config file. However, I need to be able to change to different databases based on user selection, and all the databases have the same schema objects. I then choose not to save connectionstring in App.config when building .edmx file from the wizard, and try to use the following code to dynamically build the entity object,

string myConnStr = "User ID=user1; Password=pwd1; Data Source=db1";
Entities entities = new Entities(myConnStr);

It got compiled w/o problems, however, in runtime it keeps throwing error like

Message=Keyword not supported: 'user id'.
Source=System.Data
StackTrace:
at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)
at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)
at WpfApplication1.Entities..ctor(String connectionString) in C:\DotNet4_WM\WpfApplication1\Model1.Designer.cs:line 43

I'm not sure why the same connectionstring works well in App.config, but not in code. Are there any ways to make it work? Thanks in advance.

Susane
susane_li@yahoo.com
 
Posts: 4
Joined: Fri 20 Aug 2010 15:44

Solution Found

Postby susane_li@yahoo.com » Fri 20 Aug 2010 21:02

I found the solution from a post titled "ConnectionString as parameter !!!" on Fri 09 Jan 2009 originated by Mirra - yeah!

Susane
susane_li@yahoo.com
 
Posts: 4
Joined: Fri 20 Aug 2010 15:44


Return to dotConnect for Oracle