My oracle BD search does not fetch result

Asked

Viewed 202 times

0

I have a method, using Ado.Net to bring information from BD(Oracle 11g). There is information in table(6 records) and when run by C# no record. See the code below:

public class ConexaoBanco
    {
        string conexao = ConfigurationManager.ConnectionStrings["FarmExternaConnect"].ConnectionString;
        List<string> listaArquivoFarmExterna = new List<string>();
        public bool CriaConexao()
        {
            OracleConnection conn = new OracleConnection(conexao);
            conn.Open();

            OracleCommand cmd = new OracleCommand();
            cmd.Connection = conn;
            cmd.CommandText = "select path, arquivo from gh_arquivos_farm_externa";
            cmd.CommandType = CommandType.Text;

            OracleDataReader dr = cmd.ExecuteReader();

            while(dr.Read())
            {
                listaArquivoFarmExterna.Add(dr.ToString());
                //listaArquivoFarmExterna.Add(dr.GetString(1));
            }

            return listaArquivoFarmExterna.Count > 0? true : false;
        } 
    }

The most interesting thing about this is the following situation. When I get to that line OracleDataReader dr = cmd.ExecuteReader(); and give a F10 (in debug mode), I advance and when debugging this line there is information (correct), however if I debug the variable dr along those lines while(dr.Read()), already says that:

The enumeration did not produce results

and if I go back to the top line, where there were moments ago and there were results, I have the same message. I do not know what is happening.

  • And there’s no mistake?

  • @Krismorte, I edited the original post.

  • Any other commands work? Is the connection actually being made. Try for a Try/catch to see if an exception is being generated.

1 answer

0

I killed the problem. When I debugged, I triggered the reading and as it does not come back to read the fetch again, when arriving at the while already arrived without information. It was my fault

Browser other questions tagged

You are not signed in. Login or sign up in order to post.