3

I have an application with .NET 4.0 and EF6 this is working ok with SQL Server, and now, I need use an Oracle BD In the same way. I have a model in this proyect with 5 tables and when I connect this proyect with this DB migrations add this news tables in it.

Now, I put all reference to Oracle.

Oracle.DataAccess.dll
Oracle.DataAccess.EntityFramework
Oracle.ManagedDataAccess.EntityFramework

And Put this in web.config

 <section name="Oracle.ManagedDataAccess.Client" type="OracleInternal.Common.ODPMSectionHandler, Oracle.ManagedDataAccess, Version=4.121.2.0, Culture=neutral, PublicKeyToken=89b483f429c47342"/>

I was using this conn string

<add name="ChatContext" connectionString="Data Source=serversql; Initial Catalog=database;uid=user;password=pass;" providerName="System.Data.SqlClient"/>

Now I'm trying with

  <add name="ChatContext" connectionString="Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracleserver)(PORT=1521))(CONNECT_DATA=SERVICE_NAME=oracledb)));User Id=user;Password=pass;" providerName = "Oracle.ManagedDataAccess.Client"/>

I had a "ChatContext" DB in my documents and delete it to Migrations generate a new Context file.

When i try to ejecute my code in have this error:

An error occurred accessing the database. This usually means that the connection to the database failed. Check that the connection string is correct and that the appropriate DbContext constructor is being used to specify it or find it in the application's config file.

I Generate a new MVC proyect to check if the conn string was ok, and could connect to db, and it is.

<add name="Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Oracle.ManagedDataAccess.Client;provider connection string=&quot;data source=oracledb;password=pass;persist security info=True;user id=user&quot;" providerName="System.Data.EntityClient" /></connectionStrings>
Tieson T.
  • 20,774
  • 6
  • 77
  • 92
Javysk
  • 381
  • 2
  • 16

1 Answers1

2

I think you just need to change your connection string from this:

"Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=oracleserver)(PORT=1521))(CONNECT_DATA=SERVICE_NAME=oracledb)));User Id=user;Password=pass;"

... to this instead:

"Data Source=oracledb;User Id=user;Password=pass;"

The Data Source only needs to be set to the service name.

sstan
  • 35,425
  • 6
  • 48
  • 66
  • Yes sstan, recently could solve this problem with only this code connectionString="data source=oracledb;password=pass;persist security info=True;user id=user;" but now Im having a problem with migrations, I couldnt generate this tables in db i have this new exception "ORA - 01918: users' dbo 'does not exist" Im watching this post http://stackoverflow.com/questions/27250555/oracle-manageddataaccess-entityframework-ora-01918-user-dbo-does-not-exist but I dont know what put in (schema) "UPPERCASE_SCHEMA_NAME" – Javysk Jul 17 '15 at 14:25
  • I'm just guessing, but it will probably be the userId that is the owner of the object/table. If the table is owned by the same user that you are connecting as, then maybe it's "USER" (replace "USER" with whatever you are actually using in the connection string as the "User Id" value). In Oracle, user == schema. – sstan Jul 17 '15 at 14:29