0

It's my first time trying to do stuff with Dapper and Oracle database and I'm having trouble creating a connection.

I am able to connect to database through Oracle Sql Developer, but can't connect through code.

This is my connection string:

 public static string oradb = @"Data Source=(DESCRIPTION="
      + "(ADDRESS=(PROTOCOL=TCP)(HOST=192.168.1.232)(PORT=1521))"
      + "(CONNECT_DATA=(SERVER = DEDICATED)(SERVICE_NAME=XE)));"
      + "User Id=SYSTEM;Password=root;";

This is the method in which I'm connecting

 public static IEnumerable<T> ReturnList<T>(string procedureName, DynamicParameters param)
    {
        using (SqlConnection conn = new SqlConnection(oradb))
        {
            conn.Open();  <--- here I'm getting an error
            return conn.Query<T>(procedureName, param, commandType: CommandType.StoredProcedure);
        }
    }

This is my tnsnames.ora connection:

XE =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.232)(PORT = 1521))
(CONNECT_DATA =
  (SERVER = DEDICATED)
  (SERVICE_NAME = XE)
 )
)



LISTENER_XE =
(ADDRESS = (PROTOCOL = TCP)(HOST = 192.168.1.232)(PORT = 1521))



ORACLR_CONNECTION_DATA =
(DESCRIPTION =
(ADDRESS_LIST =
  (ADDRESS = (PROTOCOL = IPC)(KEY = EXTPROC1521))
)
(CONNECT_DATA =
  (SID = CLRExtProc)
  (PRESENTATION = RO)
)
)

System.Data.SqlClient.SqlException: 'A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)'

Panagiotis Kanavos
  • 120,703
  • 13
  • 188
  • 236
Vilmantas
  • 3
  • 2
  • `SqlConnection` is the *SQL Server* connection class. You can't use it to connect to Oracle. Install and use an Oracle ADO.NET provider, like Oracle's [Oracle Data Provider for .NET](https://www.oracle.com/database/technologies/appdev/dotnet/odp.html). The class name should be something like `OracleConnection` – Panagiotis Kanavos Jan 07 '20 at 12:39
  • BTW you should post the error *text*, not a link to an image of the text. Images can't be googled, copied or compiled – Panagiotis Kanavos Jan 07 '20 at 12:41
  • Omg I'm blind, thank you! I've checked this answer before but didn't notice that it's using OracleConnection instead of SqlConnection. I watched youtube tutorial and for him SqlConnection somehow worked so I thought that's not the problem.. – Vilmantas Jan 07 '20 at 12:45

0 Answers0