Click here to Skip to main content
15,882,278 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I tried to all the possible solutions, but code is not working. Getting same error again and again.
Infact, I've installed the same from below link:

What I have tried:

string ExcelContentType = "application/";
        string Excel2010ContentType = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet";
        if (fileuploadExcel.HasFile)
            //Check the Content Type of the file 
            if (fileuploadExcel.PostedFile.ContentType == ExcelContentType || fileuploadExcel.PostedFile.ContentType == Excel2010ContentType)
                    //Save file path 
                    string filename = Path.GetFullPath(fileuploadExcel.PostedFile.FileName);
                    string DirectoryPath = Server.MapPath("UploadExcelFile/");
                    string strFilepPath = DirectoryPath + fileuploadExcel.FileName;
                    //Save File as Temp then you can delete it if you want 

                    //For Office Excel 2010  please take a look to the followng link 
                    string excelConnectionString = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=Excel 12.0 XML", strFilepPath);
                   // Create Connection to Excel Workbook   
                    using (OleDbConnection connection = new OleDbConnection(excelConnectionString))
                        OleDbCommand command = new OleDbCommand
                                ("Select * FROM [Sheet1$]", connection);


                        // Create DbDataReader to Data Worksheet 
                        using (DbDataReader dr = command.ExecuteReader())

                            // SQL Server Connection String 
                            string sqlConnectionString = ConfigurationManager.ConnectionStrings["connectionstring"].ConnectionString;

                            // Bulk Copy to SQL Server 
                            using (SqlBulkCopy bulkCopy =
                                       new SqlBulkCopy(sqlConnectionString))
                                bulkCopy.DestinationTableName = "SendMail_Emailids";
                                //Label1.Text = "The data has been exported succefuly from Excel to SQL";
                               // ScriptManager.RegisterStartupScript(Page, GetType(), "script1", "alert('Excel file successfully imported into DB');", true);
                                ClientScript.RegisterStartupScript(this.GetType(), "myalert", "alert('Excel file successfully imported into DB');", true);

                catch (Exception ex)
Updated 12-Sep-17 13:04pm
Richard Deeming 12-Sep-17 15:49pm    
If you really have tried "all possible solutions", and none of them have worked, then logically there is no solution to your problem! :)

Once you've installed the provider, this is most frequently a 64-bit vs 32-bit problem: Solved - The Microsoft.ACE.OLEDB.12.0 provider is not registered on the local machine [^]

Alternatively, since you're using the modern .xlsx file format, you could use something like EPPlus[^], ClosedXML[^], or ExcelDataReader[^] to read the Excel file.

1 solution

Did you install these[^]?

If your app is compiled targeting x64, you have to use the 64-bit version of the runtime.

If your app is compiled targeting x86, you have to use the 32-bit version.

If your app is compiled targeting AnyCPU, it depends on which O/S your app is running on:
32-bit Windows, must use the 32-bit runtime.
64-bit Windows, must use the 64-bit runtime.
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900