1
        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}'"

Chandikumar
  • 139
  • 11
  • Possible duplicate of http://stackoverflow.com/questions/5721564/multi-threading-in-vba – Ahmad Jul 02 '15 at 09:34
  • Try the solution in this answer: http://stackoverflow.com/a/27245931/736172 – Ahmad Jul 02 '15 at 09:35
  • 1
    Hi Ahmad, it is a c# code that simply reads emailids in excel. It doesnt require multithreading. it simply stuck at connExcel.Close(); for 20-40 seconds then gives output. – Chandikumar Jul 02 '15 at 10:07
  • 1
    I run the same code on server and its working fine. but on local machine it is causing issue. I am using visual studio express edition. – Chandikumar Jul 03 '15 at 06:44
  • @Chandikumar Hi Chandik did you ever find a solution to this? – Bassie Jun 12 '17 at 21:18
  • using System.Runtime.InteropServices; using System.Threading.Tasks; using Excel = Microsoft.Office.Interop.Excel; @Bassie I included these three things. and used only one connection string for both xls and xlsx. connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + filePath + ";Extended Properties=\"Excel 12.0;HDR=No;IMEX=-1\""; – Chandikumar Jun 13 '17 at 09:53
  • @Chandikumar Ah, thanks for your response, but I am seeing this error when using `ACE.OLEDB` to connect to MS Acccess .. Do you have any idea if Access actually supports extended properties? Can't find any examples – Bassie Jun 13 '17 at 10:08

0 Answers0