I have to display data from multiple SQLite db files (200 approx) in a grid.
I am running a loop for the number of db files in the directory and for each of the file open()
connection, get the data, add it in a new grid row and then close the connection.
Now for 200 files I am having to open and close 200 SQLite connections. Obviously, this is making my web page containing the grid respond too slowly and almost takes 2 mins to load the page.
Is there a way to read thru all these files in a faster way?
Here is the code I have:
FileInfo[] dbFiles1 = dbDir.GetFiles("*.db");
int fileCount = dbFiles1.Count();
DataTable dtable = new DataTable();
dtable.Columns.Add("file_name", typeof(string));
dtable.Columns.Add("TIME (Central)", typeof(string));
for (int i = 0; i < fileCount; i++)
{
DataTable dTab = new DataTable();
SQLiteCommand sql_cmd;
SQLiteDataAdapter sql_Da;
DataSet dSet = new DataSet();
SQLiteConnectionStringBuilder builder = new SQLiteConnectionStringBuilder();
builder.FailIfMissing = true;
builder.DataSource = dirPath + "\\" + dirName + "\\" + reportName;
SQLiteConnection sql_con = new SQLiteConnection(builder.ConnectionString);
sql_con.Open();
sql_cmd = sql_con.CreateCommand();
string commandText = "Select.........";
sql_Da = new SQLiteDataAdapter(commandText, sql_con);
dSet.Reset();
sql_Da.Fill(dSet);
dTab = dSet.Tables[0];
sql_con.Close();
DataTable dtable = new DataTable();
dtable.ImportRow(dTab.Rows[0]);
}
GridView.DataSource = dtable;
GridView.DataBind();