Click here to Skip to main content
15,901,122 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ERROR: The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

C#
protected void Button1_Click(object sender, EventArgs e)
        {


            if (FileUpload1.HasFile)
            {
                string path = string.Concat((Server.MapPath("~/temp/" + FileUpload1.FileName)));
                FileUpload1.PostedFile.SaveAs(path);

               
                OleDbConnection OleDbcon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;server=" + path + ";Extended Properties=Excel 12.0;");

                OleDbCommand cmd = new OleDbCommand("SELECT * FROM [Sheet1$]", OleDbcon);
                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter(cmd);
                OleDbcon.Open();
               DbDataReader dr = cmd.ExecuteReader();

               string connectionString = @"Data Source=.\sqlexpress;Initial Catalog=testdb;User Id=abc; Password=abc123;";
               con);


               SqlBulkCopy bulkInsert = new SqlBulkCopy(connectionString);
                bulkInsert.DestinationTableName = "table_temp";
                bulkInsert.WriteToServer(dr);
                OleDbcon.Close();
                Array.ForEach(Directory.GetFiles((Server.MapPath("~/temp/"))), File.Delete);
                Label1.ForeColor = Color.Green;
                Label1.Text = "successfully inserted";

            }
            else
            {
                Label1.ForeColor = Color.Red;
                Label1.Text = "Please select the File";
            }
}
}
Posted
Updated 21-Jul-14 6:07am
v2
Comments
Thanks7872 21-Jul-14 6:19am    
Google gave me about 7,330 results in 0.29 seconds by just searching the error text.

 
Share this answer
 
Comments
Maciej Los 21-Jul-14 13:58pm    
+5
CPallini 21-Jul-14 15:09pm    
Thank you :-)
While working with Microsoft Access Database connectivity with with ADO.NET you might have received this error
 
The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine
The 'Microsoft.Jet.oledb.4.0' provider is not registered on the local machine
etc ...
Solution:-
You need to change the Solution Platform from "Any CPU" to "x86". The steps are given below
1. Right Click on the Solution File in Solution Explorer
2. Click on the Configuration Manager.
3.Click on the Active Platform Drop down, If x86 is already there then select that, else Click on New 
4.Select x86 from the new platform dropdown 
5.Compile and Run your application, 
 
If you are still facing the issue then try installing Office System Driver 


OLEDB Provider is Not Registered on the Local Machine[^]
 
Share this answer
 

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



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