I have a problem with ORACLE, System.Data.OracleClient

0

I have a stored procedure

Oracle IDE: 4.0.3.16.84 and Visual Studio 2015

OracleConnection con = new OracleConnection();
        OracleCommand oracommand = new OracleCommand();
        OracleDataReader lector;
        con.ConnectionString = "Data Source = XXXX; User Id = XXXX; Password = XXXX; Unicode = true;";
        try
        {
            con.Open();
            oracommand.Parameters.Add("consec", Oracle.ManagedDataAccess.Client.OracleDbType.Int32).Direction = ParameterDirection.Output;
            oracommand.ExecuteNonQuery();
            LNumDoc.Text = (string)(oracommand.Parameters["consec"].Value);
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message, "XXXX.");
        }
        con.Close();

When I run it I get this error: System.Data.OracleClient requires version 8.1.7 or later of the Oracle client software

    
asked by Saul Salazar 17.08.2018 в 00:24
source

1 answer

1

At first I recommend you remove the references of

  

System.Data.OracleClient;

and then install the oracle connector

  

Install-Package Oracle.ManagedDataAccess -Version 12.2.1100

After you change the Connection String in this way

        const string _protocol = "TCP";
        const string _schema = "xx";
        const string _pswSchema = "xx";
        const string _host = "xx";
        const string _port = "1521";
        const string _serviceName = "xx";

        const string _cnnString = "(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=" + _protocol + ")(HOST=" + _host + ")"
                             + "(PORT=" + _port + ")))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=" + _serviceName + ")))";

Then in your code

    using Oracle.ManagedDataAccess.Client;

    //
    var oracleConnectionStringBuilder = new OracleConnectionStringBuilder
            {
                DataSource = _cnnString,
                UserID = _schema ,
                Password = _pswSchema 
            };

    string cnnStringFormat2 = "Data Source=" + _cnnString + ";User Id="+ _schema + ";Password="+ _pswSchema ;
    OracleConnection con = new OracleConnection(oracleConnectionStringBuilder.ToString());
    OracleCommand oracommand = new OracleCommand("get_secuencia",con);
    oracommand.CommandType = CommandType.StoredProcedure;
    OracleDataReader lector;

    try
    {
       con.Open();
       oracommand.Parameters.Add("consec", Oracle.ManagedDataAccess.Client.OracleDbType.Int32).Direction = ParameterDirection.Output;
       oracommand.ExecuteNonQuery();
       LNumDoc.Text = oracommand.Parameters["consec"].Value.ToString();
    }
    catch (Exception ex)
    {
        MessageBox.Show(ex.Message, "XXXX.");
    }
    con.Close();
    
answered by 17.08.2018 / 00:41
source