Should I use OracleClient or ADODB to connect to an Oracle Database using c#?

578 views Asked by At

I am trying to connect to an Oracle database using c#. I see that I have two options: using System.Data.OracleClient; or using ADODB;

I am familiar with MySQL which is why OracleClient is easier for me to understand and make use of. However, I see that when I use it c# says it is deprecated. That makes me wonder whether my code with OracleClient would work like 1-2 years from now on.

What should I do?

Below is my code using OracleClient:

public class DataHelper
    {
        public OracleConnection connection;
        String connectionString;

        public DataHelper()
        {
            connectionString = "this should be connection string";
            
            connection = new OracleConnection(connectionString);
        }

        public List<Machine> GetAllMachines()
        {
            List<Machine> temp= new List<Machine>();
            using (OracleConnection connection = new OracleConnection(connectionString))
            {
                string queryString = "SELECT * FROM MACHINES";
                OracleCommand command = new OracleCommand(queryString);
                try
                {
                    command.Connection = connection;
                    connection.Open();
                    command.CommandType = CommandType.Text;
                    //command.ExecuteNonQuery();
                    OracleDataReader reader = command.ExecuteReader();
                    int machineNr, nrOfLinesPerCm;
                    double cycleTime, currentTime, heightOfLamallae;
                    string machineType;
                    while (reader.Read())
                    {
                        machineNr = Convert.ToInt32(reader["MACHINE_NR"]);
                        cycleTime = Convert.ToDouble(reader["CYCLE_TIME"]);
                        currentTime = Convert.ToDouble(reader["CURRENT_TIME"]);
                        machineType = Convert.ToString(reader["TYPE"]);
                        nrOfLinesPerCm = Convert.ToInt32(reader["NR_OF_LINES_PER_CM"]);
                        heightOfLamallae = Convert.ToDouble(reader["HEIGHT_OF_LAMALLAE"]);
                        temp.Add(new Machine(machineNr, cycleTime, currentTime, nrOfLinesPerCm, heightOfLamallae, machineType));
                    }
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message);
                }
                finally
                {
                    connection.Close();
                }
            }
            return temp;
        }
        
    } 

If you recommend ADODB how would you implement this with it?

2

There are 2 answers

2
Derviş Kayımbaşıoğlu On

Oracle Client is not deprecated but yours is. You can download Oracle.ManagedDataAccess (for .Net) or Oracle.ManagedDataAccess.Core (for .Net Core) from Nuget. These are standalone clients which they dont need native client installation.

0
Jesús López On

You should not use either, ADODB is a COM ancient library and as you know System.Data.OracleClient is deprecated and it requires to install Oracle native client.

You should use Oracle.ManagedDataAccess on .Net Framework and Oracle.ManagedDataAccess.Core on .net core. Both libraries have no dependencies on native libraries. Just install the nuget pacakage and it will work on any machine that has .Net Framework or .net core respectively.