0

I am trying to connect to oracle data base using below code.

using System;
using System.Collections.Generic;
using System.Data;

using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {

            string connectionString =
                "Data Source=a;User Id=id;Password=pwd;";

            OracleConnection con = new OracleConnection(connectionString);
            con.Open();
            Console.WriteLine("Connected to Oracle Database {0}", con.ServerVersion);
            con.Dispose();

            Console.WriteLine("Press RETURN to exit.");
            Console.ReadLine();

        }

    }
}

Its throwing exception saying:

An unhandled exception of type 'Oracle.ManagedDataAccess.Client.OracleException' occurred in Oracle.ManagedDataAccess.dll

Additional information: ORA-12514: TNS:listener does not currently know of service requested in connect descriptor.

Can any body correct me what was going wrong with the above code?

Irshad
  • 3,071
  • 5
  • 30
  • 51

1 Answers1

0

the issues maybe is the connection string, if you haven't TNS name "a" registered you can try this

string connectionString = 
"Data Source=localhost:1521/xe;User Id=USERDB;Password=pwd";

by default XE is name for oracleservice where

Data Source -> localhost:1521/xe (ip:port/servicename)

User Id -> you Oracle user

Password -> you Oracle password

Community
  • 1
  • 1
David Zambrano
  • 650
  • 7
  • 13