OLEDB conection goes down when processing a large number of files


I have a problem with oledb in C # turns out that it is a console that reads files .xlsx of a folder (170 files in total) but when it goes in reading No. 120 it falls and the error is "Unknown"

OleDbConnection Econ;
Econ = new OleDbConnection(constr);
string qTotal = string.Format("Select * from[Sheet1$]");
string qTotalvalores = string.Format("Select * from[Sheet1$B12:H755]");
OleDbCommand ETotal = new OleDbCommand(qTotal, Econ);
OleDbCommand Etotal2 = new OleDbCommand(qTotalvalores, Econ);

termino = termino + 1;

Econ.Open(); //al procesar el archivo n° 120 //Se cae la conexion en Econ.Open();

// Creacion de Dataset para cada uno de los contructores
DataSet dsTotal = new DataSet();
DataSet dsTotal2 = new DataSet();
OleDbDataAdapter odaTotal = new OleDbDataAdapter(qTotal, Econ);
OleDbDataAdapter odaTotal2 = new OleDbDataAdapter(qTotalvalores, Econ);


asked by Joel Baez 10.09.2018 в 22:57

1 answer


I would recommend that the code be defined within a block using to ensure that objects are destroyed correctly

using(OleDbConnection Econ= new OleDbConnection(constr)){

    //resto del codigo

in this way the garbage collector ensures that the object is destroyed effectively and leaves no orphaned connections

It is not necessary to define a Close () of the connection at the end, when you exit the scope of using the objects in that field are destroyed

answered by 11.09.2018 / 09:20