0 Replies Latest reply on Mar 30, 2020 7:07 PM by thomashg

    Error Connecting to Oracle DB with Entity Framework: "No connection could be made because the target machine actively refused it"




      I have been attempting to connect to an Oracle database using Visual Studio 2019 and ODT 19.3. I can successfully connect to the database using Server Explorer, but when I run the code and have to retrieve records using EntityFramework, I get the following exception (the first line is the initial exception, all additional lines are inner exceptions):


      "The underlying provider failed on Open." (System.Data.Entity.Core.EntityException)

      "ORA-12541: TNS: No listener" (Oracle.ManagedDataAccess.Client.OracleException)

      "ORA-12541: TNS: No listener" (OracleInternal.Network.NetworkException)

      "No connection could be made because the target machine actively refused it" (System.Net.Sockets.SocketException)


      I have two hunches on what could be going wrong, but need more guidance.


      1. It appears that it is trying to access a target machine of (localhost) with port 1521. The database I am attempting to connect to is on a remote server, and the port number I am attempting to reach is 1522 in my tnsnames.ora, which is located in the default location C:\Users\myusername\Oracle\network\admin. Could this not be ready the tns correctly?
      2. When I click "Properties" on the database connection in Server Explorer, it says the version is, despite all my oracle products having version 19.x. Could this be the Oracle version of the database itself? Picture of properties is below:




      Here are the relevant tools and versions:


      Microsoft Visual Studio Enterprise 2019 version 16.4.5

      ODT version 19.3

      Oracle Client version 19.3

      EntityFramework version 6.4

      Oracle.ManagedDataAccess version 19.6

      Oracle.ManagedDataAccess.EntityFramework version 19.6


      Thanks for your time