Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Oracle Db Code First Connection String Issue

7677f076-1fd4-4936-9e13-190e565bcb14Nov 21 2015 — edited Nov 21 2015

Hi,

Can any one tell me the how to set manually an oracle connection string in a dbcontext object with Entity framework code first

I read the below article, but the answer didn't work for me.

http://stackoverflow.com/questions/7894086/how-to-set-manually-an-oracle-connection-string-in-a-dbcontext

My requirement is to instantiate the dbcontext object with connection string value dynamically.

var orcDB = new OracleDBContext(“DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));USER ID=system;PASSWORD=123456”);


It works well with the case 1 and 2 and in case 3 it fails:

  • Case 1:

o   The connection string name should match the application context name.

<connectionStrings>

<add name="OracleDBContext" connectionString="**********" providerName="Oracle.ManagedDataAccess.Client" />

</connectionStrings>

o   Then, Context object can be used like below to establish the connection.

var oracleDbContext = new OracleDBContext();

  • Case 2:

o   The connection string name can be passed in context object and connection string should be part of config file

<connectionStrings>

<add name="Oracle.ConnectionString" connectionString="DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));USER ID=system;PASSWORD=zxcv1234"  providerName="Oracle.ManagedDataAccess.Client" />

</connectionStrings>

o   Context object can be used like below to establish the connection.

  • varnewOracleDBContext(“Oracle.ConnectionString”);
  • Case 3:

o    It fails to establish the connection if we pass the connection string value to the context object dynamically like below.

        • var new OracleDBContext(“DATA SOURCE=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=XE)));USER ID=system;PASSWORD=zxcv1234”);

o   Reason:

        • The entity framework not able to parse the oracle database connection string value and fails to instantiate the database connection dependencies because it will try parsing the connection string value in same way like how it used for sql connection string and there it fails.

Is there any solution to this problem?


Thanks,

Kiran

Message was edited by: 7677f076-1fd4-4936-9e13-190e565bcb14

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Dec 19 2015
Added on Nov 21 2015
1 comment
638 views