OleDbConnection close method taking long execution time

让人想犯罪 __ 提交于 2020-01-30 09:45:07

问题


        conStr = String.Format(conStr, FilePath, isHDR);
        OleDbConnection connExcel = new OleDbConnection(conStr);
        OleDbCommand cmdExcel = new OleDbCommand();
        OleDbDataAdapter oda = new OleDbDataAdapter();
        DataTable dt = new DataTable();
        cmdExcel.Connection = connExcel;

        //Get the name of First Sheet
        connExcel.Open();
        DataTable dtExcelSchema;
        dtExcelSchema =            connExcel.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
        string SheetName = dtExcelSchema.Rows[0]["TABLE_NAME"].ToString();
        connExcel.Close();

I am using above code to read excel. But it stuck at connExcel.Close(); for few seconds and then move to next statement. This is causing late processing on the page. Any suggestions??

Updating my question to give more details.

test case:- I uploaded an xls file it took normal time. I uploaded an xlsx file it halt at connExcel.close() for 25sec. Now i uploaded an xls file and it halt for xls also.

i have used following connection strings

for xls :- connectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source={0}; Extended Properties='Excel 8.0;HDR={1}'"

for xlsx :- connectionString="Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}; Extended Properties='Excel 8.0;HDR={1}'"

来源:https://stackoverflow.com/questions/31180822/oledbconnection-close-method-taking-long-execution-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!