0

please need your help .

in my application i am using the file upload control to import excel file into database. when i am running the application in localhost it is working fine, but after deploying the application when i am running the application from same or other machine, the file upload control is not working and get the below error.

The 'Microsoft.ACE.OLEDB.12.0' provider is not registered on the local machine.

Uploading code :

if (FileUpload.HasFile)
{

    string path = string.Concat((Server.MapPath("~/Temp/" + FileUpload.FileName)));
    FileUpload.PostedFile.SaveAs(path);
    OleDbConnection OleDbCon = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + path + ";Extended Properties=Excel 12.0;");

    OleDbCommand cmd = new OleDbCommand("Select * from [Sheet1$]", OleDbCon);
    OleDbDataAdapter objAdapter = new OleDbDataAdapter(cmd);


    OleDbCon.Open();
    DbDataReader dr = cmd.ExecuteReader();
    string con_str = ConfigurationManager.ConnectionStrings[1].ConnectionString;

    SqlBulkCopy bulkInsert = new SqlBulkCopy(con_str);
    bulkInsert.DestinationTableName = "[dbo].[HP_temp]";
    bulkInsert.WriteToServer(dr);
    OleDbCon.Close();

    Array.ForEach(Directory.GetFiles((Server.MapPath("~/Temp/"))), File.Delete);
    Label_UploadMsg.ForeColor = Color.Green;
    Label_UploadMsg.Text = "Imported sucess";

}
else
{
    Label_UploadMsg.ForeColor = Color.Red;
    Label_UploadMsg.Text = "Error";
}

1 Answers1

0

Install the Microsoft Access Database Engine 2010 Redistributable. https://www.microsoft.com/en-gb/download/details.aspx?id=13255

Pay particular attention to the type of version (32/64 bit).

Reference: http://www.mikesdotnetting.com/article/280/solved-the-microsoft-ace-oledb-12-0-provider-is-not-registered-on-the-local-mac

felix
  • 131
  • 1
  • 1
  • 6