0

I am using VS 2015 and I would like to make a connect on Oracle 12c DB instaled on docker.
I have already created all credentials necessary for succefull login (it was tested by SQLDeveloper).

Now I need in C# make a succesfull

  • Open ()
  • Disconnect()
  • Query process (Select)
  • Inserty/Update/Delete - process

Do you have some ide for working example? Because this is not working:
this is my code for DB:

using Oracle.ManagedDataAccess.Client;

namespace namespace_name_x
{
    class OraConnect
    {
        public OracleConnection con;
        public void Connect()
        {
            con = new OracleConnection();
            con.ConnectionString = "User Id=USERNAME;Password=PASSWORD;Data Source=localhost:1521/ORCLCDB.localdomain;Pooling = false;";
            con.Open();
            Console.WriteLine("Connected to Oracle" + con.ServerVersion);
        }

        public void Close()
        {
            con.Close();
            con.Dispose();
        }
    }
}

And this is my code in main

using Oracle.ManagedDataAccess.Client;
namespace namespace_name_x
class Program
    {
        static void Main(string[] args)
        {
            //Create a connection to Oracle
            OraConnect ot = new OraConnect();
            ot.Connect();
            string cmdstr = "SELECT NAME FROM ANY_TABLE";            

            OracleCommand cmd = new OracleCommand(cmdstr, ot);
            OracleDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                Console.WriteLine("Employee Name: " + reader.GetString(0));
            }
etc...

and it is not working. It is only SELECT query.
Do you have any idea?
thank you

PS: advices from this link are not working! (How to connect Oracle 12c data base through console application)

Anton Lieskovsky
  • 179
  • 2
  • 3
  • 14
  • 1
    What do you mean "not working"? Can you tell us exactly the error you receive and where. – jason.kaisersmith Mar 03 '21 at 13:18
  • in line OracleCommand cmd = new OracleCommand(cmdstr, ot); should be error: Argument 2: cannot convert from 'namespace_name_x.OraConnect' to 'Oracle.ManagedDataAccess.Client.OracleConnection' – Anton Lieskovsky Mar 05 '21 at 14:21

0 Answers0