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:

https://www.microsoft.com/en-us/download/details.aspx?id=13255

What I have tried:

C#
string ExcelContentType = "application/vnd.ms-excel";
        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)
            {
                try
                {
                    //Save file path 
                    string filename = Path.GetFullPath(fileuploadExcel.PostedFile.FileName);
                    string DirectoryPath = Server.MapPath("UploadExcelFile/");
                    string strFilepPath = DirectoryPath + fileuploadExcel.FileName;
                    Directory.CreateDirectory(DirectoryPath);
                    //Save File as Temp then you can delete it if you want 
                    fileuploadExcel.SaveAs(strFilepPath);

                    //For Office Excel 2010  please take a look to the followng link  http://social.msdn.microsoft.com/Forums/en-US/exceldev/thread/0f03c2de-3ee2-475f-b6a2-f4efb97de302/#ae1e6748-297d-4c6e-8f1e-8108f438e62e 
                    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);

                        connection.Open();

                        // 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";
                                bulkCopy.WriteToServer(dr);
                                //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)
                {
                    Response.Write(ex.Message);
                }
            }
        }
Posted
Updated 12-Sep-17 13:04pm
v4
Comments
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