I have to list about 900000 records from a database, and then do a tour in C # with a FOR, but being too many records I get the error of waiting time exhausted. Is there any way to accelerate this? This is my SP in SQL: The result is 870000 records.
create proc spSNMMan_SP_Listar_Guias_xMes_xAño
@mes int,
@año int
as
select (g.GUIA_DET_NRO_REF)'N° de Guía',
guia_det_fch_emi Fecha_Guia
from guia_detalle_nacional g WITH(NOLOCK)
where g.NWT_CON_IMG = 1 and
MONTH(guia_det_fch_emi)=@mes and
year(guia_det_fch_emi)=@año
This is my FOR in C #:
void Listar() {
try
{
CN_Guias guias = new CN_Guias();
DateTime Hoy = DateTime.Today;
string fecha_actual = Hoy.ToString("dd/MM/yyyy");
string mes, año;
mes = txt_mes.Text;
año = txt_anno.Text;
if (txt_ruta.Text == "")
{
//MessageBox.Show("Ingresar Ruta por favor.!!!");
MessageBox.Show("Ingresar Ruta por favor.!!!", "Ingresar Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (txt_mes.Text == "")
{
MessageBox.Show("Ingrese el Mes por favor.!!!", "Ingresar Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else if (txt_anno.Text == "")
{
MessageBox.Show("Ingrese el Año por favor.!!!", "Ingresar Datos", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
int cantidad_imagen_db = guias.Listar_Guias_xMes_xAño
(Convert.ToInt32(mes), Convert.ToInt32(año)).Rows.Count;
pgb_cargando.Visible = true;
pgb_cargando.Maximum = cantidad_imagen_db;
pgb_cargando.Step = 1;
pgb_cargando.Value = 0;
//INICIO FOR
btn_listar.Enabled = false;
for (int o = 0; o < cantidad_imagen_db; o++) //Recorre la cantidad de Imagenes de la DB
{
string nom_imagen_db = guias.Listar_Guias_xMes_xAño
(Convert.ToInt32(mes), Convert.ToInt32(año)).Rows[o][0].ToString().TrimEnd(' ');
var ruta_imagen = Path.Combine(txt_ruta.Text, nom_imagen_db + ".tif");
if (!File.Exists(ruta_imagen))
{
string f_guia = guias.Listar_Guias_xMes_xAño(Convert.ToInt32(mes),
Convert.ToInt32(año)).Rows[o][1].ToString();
objguias.InsertarGuiasValidadas(nom_imagen_db,
Convert.ToDateTime(f_guia), Convert.ToDateTime(fecha_actual), 0);}
}
MessageBox.Show("Se realizo la validación correctamente");
btn_listar.Enabled = true;
Limpiar();
//FIN FOR
//btn_validar.Enabled = true;
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message.ToString());
}
If anyone has any ideas that can help me, I will appreciate sharing your knowledge.
Thank you.