Vimlesh Mishra

Vimlesh Mishra

  • 1.6k
  • 145
  • 26.1k

Microsoft.ACE.OLEDB.4.0 provider is not registered

Dec 12 2013 8:02 AM
Server Error in '/' Application.The 'Microsoft.ACE.OLEDB.4.0' provider is not registered on the local machine.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
 
Exception Details: System.InvalidOperationException: The 'Microsoft.ACE.OLEDB.4.0' provider is not registered on the local machine.

Source Error:

Line 50:             if (con.State == ConnectionState.Closed) Line 51:             { Line 52:                 con.Open(); Line 53:             } Line 54:


Source File: f:\IIS Applications\Dot Net\AuditBilling2010\frmexcelfile.aspx.cs    Line: 52

Stack Trace:

[InvalidOperationException: The 'Microsoft.ACE.OLEDB.4.0' provider is not registered on the local machine.]    System.Data.OleDb.OleDbServicesWrapper.GetDataSource(OleDbConnectionString constr, DataSourceWrapper& datasrcWrapper) +1761342    System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection) +1777302    System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject) +100    System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup) +43    System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection) +6296143    System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory) +6296606    System.Data.OleDb.OleDbConnection.Open() +48    frmexcelfile.Button1_Click(Object sender, EventArgs e) in f:\IIS Applications\Dot Net\AuditBilling2010\frmexcelfile.aspx.cs:52    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +154    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +3691


Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.1
 
My Code Is
  1. using System;  
  2. using System.Collections.Generic;  
  3. using System.Linq;  
  4. using System.Web;  
  5. using System.Web.UI;  
  6. using System.Web.UI.WebControls;  
  7. using System.Data.SqlClient;  
  8. using System.IO;  
  9. using System.Configuration;  
  10. using System.Data.OleDb;  
  11. using System.Data;  
  12.   
  13.   
  14. public partial class frmexcelfile : System.Web.UI.Page  
  15. {  
  16.     protected void Page_Load(object sender, EventArgs e)  
  17.     {  
  18.   
  19.     }  
  20.     string forthddate;  
  21.     protected void Button1_Click(object sender, EventArgs e)  
  22.     {  
  23.         string strConnection1 = Convert.ToString(ConfigurationManager.ConnectionStrings["AuditBilling"]);  
  24.         SqlConnection con1 = new SqlConnection(strConnection1);  
  25.         con1.Open();  
  26.         String strConnection = "ConnectionString";  
  27.         string connectionString = "";  
  28.         if (FileUpload1.HasFile)  
  29.         {  
  30.             string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);  
  31.             string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);  
  32.             string fileLocation = Server.MapPath("~/App_Exel_Updata_Fiele/" + fileName);  
  33.             FileUpload1.SaveAs(fileLocation);  
  34.             if (fileExtension == ".xls")  
  35.             {  
  36.                 //connectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=Excel 8.0";  
  37.                 connectionString = "Provider=Microsoft.ACE.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=Excel 8.0;Persist Security Info=False";  
  38.             }  
  39.             else if (fileExtension == ".xlsx")  
  40.             {  
  41.                 connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";  
  42.   
  43.             }  
  44.             OleDbConnection con = new OleDbConnection(connectionString);  
  45.             OleDbCommand cmd = new OleDbCommand();  
  46.             cmd.CommandType = System.Data.CommandType.Text;  
  47.             cmd.Connection = con;  
  48.             OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);  
  49.             DataTable dtExcelRecords = new DataTable();  
  50.             if (con.State == ConnectionState.Closed)  
  51.             {  
  52.                 con.Open();  
  53.             }  
  54.   
  55.              
  56.             DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  57.             string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();  
  58.             cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";  
  59.             dAdapter.SelectCommand = cmd;  
  60.             dAdapter.Fill(dtExcelRecords);  
  61.             SqlCommand cmdtr = new SqlCommand("truncate table dbo.Temp_Insert_Exel_TBL", con1);  
  62.             cmdtr.ExecuteNonQuery();  
  63.   
  64.             // ------Data Table Used Update Data---------------------  
  65.   
  66.             try  
  67.             {  
  68.                 foreach (DataRow row in dtExcelRecords.Rows) // Loop over the rows.  
  69.                 {  
  70.                     string str1 = row["Bill No"].ToString();  
  71.   
  72.                     string str2 = row["Associate Sign Date"].ToString();  
  73.                     //DateTime firstdate = DateTime.Parse(str2);  
  74.                     string firstdate = Convert.ToDateTime(str2).ToString("yyyy-MM-dd h:mm tt");  
  75.                     string str3 = row["Signed By Manager Date"].ToString();  
  76.                     string seconddate = Convert.ToDateTime(str3).ToString("yyyy-MM-dd h:mm tt");  
  77.                     //DateTime seconddate = DateTime.Parse(str3);  
  78.                     string str4 = row["Submitted to AC Date"].ToString();  
  79.                     string thirdddate = Convert.ToDateTime(str4).ToString("yyyy-MM-dd h:mm tt");  
  80.                     //DateTime thirdddate = DateTime.Parse(str3);  
  81.                     string str5 = row["Payment Release Date"].ToString();  
  82.                     if (str5 == "")  
  83.                     {  
  84.                         str5 = "NULL";  
  85.                         //string forthddate = Convert.ToDateTime(str5).ToString("yyyy-MM-dd h:mm tt");  
  86.                     }  
  87.                     else  
  88.                     {  
  89.                         forthddate = Convert.ToDateTime(str5).ToString("yyyy-MM-dd h:mm tt");  
  90.                     }  
  91.                     //DateTime forthddate = DateTime.Parse(str3);  
  92.                     string str6 = row["Status"].ToString();  
  93.                     string str7 = row["Cheque Date"].ToString();  
  94.                     string str8 = row["Cheque No"].ToString();  
  95.                     string str9 = row["Cheque Amount"].ToString();  
  96.                     string str10 = row["TDS Amount"].ToString();  
  97.                     int str6cn = 1;  
  98.                     //str6 = 1;DateTime date = DateTime.ParseExact(strDate, "dd/mm/YYYY", null)  
  99.                     //convert(varchar(20),GETDATE(),101)+ ' '+convert(varchar(20),GETDATE(),108)+ ' ' +right(convert(varchar(30),GETDATE(),109),0)  
  100.                     //SqlCommand update = new SqlCommand("UPDATE dbo.Temp_Insert_Exel_TBL set AssociateSigndate='" + str2 + "',manager_sign_dt='" + str3 + "',submitted_to_acct_dt='" + str4 + "',payment_release_dt='" + str5 + "',bill_status='" + str6 + "',Chq_dt='" + str7 + "',Chq_no='" + str8 + "',Chq_amt='" + str9 + "',TDS_Amt='" + str10 + "' WHERE BillNo='" + str1 + "'", con1);  
  101.                     //SqlCommand update = new SqlCommand("UPDATE dbo.Temp_Insert_Exel_TBL_update set AssociateSigndate='" + firstdate + "',manager_sign_dt='" + seconddate + "',submitted_to_acct_dt='" + thirdddate + "',payment_release_dt='" + forthddate + "',bill_status='" + str6cn + "',Chq_dt=" + str7 + ",Chq_no='" + str8 + "',Chq_amt='" + str9 + "',TDS_Amt='" + str10 + "' WHERE BillNo='" + str1 + "'", con1);  
  102.                     SqlCommand update1 = new SqlCommand("IF NOT EXISTS(SELECT BillNo from dbo.Temp_Insert_Exel_TBL_update where BillNo='" + str1 + "') " + "insert into dbo.Temp_Insert_Exel_TBL(BillNo,AssociateSigndate,manager_sign_dt,submitted_to_acct_dt,payment_release_dt,bill_status,Chq_dt,Chq_no,Chq_amt,TDS_Amt) VALUES('" + str1 + "','" + firstdate + "','" + seconddate + "','" + thirdddate + "','" + str5 + "','" + str6 + "','" + str7 + "','" + str8 + "','" + str9 + "','" + str10 + "')" + "else " + "UPDATE dbo.Temp_Insert_Exel_TBL_update set AssociateSigndate='" + firstdate + "',manager_sign_dt='" + seconddate + "',submitted_to_acct_dt='" + thirdddate + "',payment_release_dt='" + forthddate + "',bill_status='" + str6cn + "',Chq_dt=" + str7 + ",Chq_no='" + str8 + "',Chq_amt='" + str9 + "',TDS_Amt='" + str10 + "' WHERE BillNo='" + str1 + "'", con1);  
  103.                     update1.ExecuteNonQuery();  
  104.   
  105.   
  106.                 }  
  107.                 //MSGLABLE.Text = "Record Upload Success Fully";  
  108.                 gridviesbind();  
  109.             }  
  110.             catch (Exception ex)  
  111.             {  
  112.                 MSGLABLE.Text = ex.Message;  
  113.   
  114.             }  
  115.   
  116.             // gridviesbind();  
  117.             con.Close();  
  118.         }  
  119.   
  120.         // string strConnection1 = Convert.ToString(ConfigurationManager.ConnectionStrings["AuditBilling"]);  
  121.         //SqlConnection con1 = new SqlConnection(strConnection1);  
  122.         //con1.Open();  
  123.         //String strConnection = "ConnectionString";  
  124.         //string connectionString = "";  
  125.         //if (FileUpload1.HasFile)  
  126.         //{  
  127.         //    string fileName = Path.GetFileName(FileUpload1.PostedFile.FileName);  
  128.         //    string fileExtension = Path.GetExtension(FileUpload1.PostedFile.FileName);  
  129.         //    string fileLocation = Server.MapPath("~/App_Exel_Updata_Fiele/" + fileName);  
  130.         //    FileUpload1.SaveAs(fileLocation);  
  131.         //    if (fileExtension == ".xls")  
  132.         //    {  
  133.         //        connectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=2\"";  
  134.         //    }  
  135.         //    else if (fileExtension == ".xlsx")  
  136.         //    {  
  137.         //        connectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileLocation + ";Extended Properties=\"Excel 12.0;HDR=Yes;IMEX=2\"";  
  138.         //    }  
  139.         //    OleDbConnection con = new OleDbConnection(connectionString);  
  140.         //    OleDbCommand cmd = new OleDbCommand();  
  141.         //    cmd.CommandType = System.Data.CommandType.Text;  
  142.         //    cmd.Connection = con;  
  143.         //    OleDbDataAdapter dAdapter = new OleDbDataAdapter(cmd);  
  144.         //    DataTable dtExcelRecords = new DataTable();  
  145.         //    con.Open();  
  146.         //    DataTable dtExcelSheetName = con.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);  
  147.         //    string getExcelSheetName = dtExcelSheetName.Rows[0]["Table_Name"].ToString();  
  148.         //    cmd.CommandText = "SELECT * FROM [" + getExcelSheetName + "]";  
  149.         //    dAdapter.SelectCommand = cmd;  
  150.         //    dAdapter.Fill(dtExcelRecords);  
  151.         //      // ------Data Table Used Update Data---------------------  
  152.   
  153.         //    try  
  154.         //    {  
  155.         //        foreach (DataRow row in dtExcelRecords.Rows) // Loop over the rows.  
  156.         //        {  
  157.         //            string str1 = row["Bill No"].ToString();  
  158.   
  159.         //            string str2 = row["Associate Sign Date"].ToString();  
  160.         //            //DateTime firstdate = DateTime.Parse(str2);  
  161.         //            string firstdate = Convert.ToDateTime(str2).ToString("yyyy-MM-dd h:mm tt");  
  162.         //            string str3 = row["Signed By Manager Date"].ToString();  
  163.         //            string seconddate = Convert.ToDateTime(str3).ToString("yyyy-MM-dd h:mm tt");  
  164.         //            //DateTime seconddate = DateTime.Parse(str3);  
  165.         //            string str4 = row["Submitted to AC Date"].ToString();  
  166.         //            string thirdddate = Convert.ToDateTime(str4).ToString("yyyy-MM-dd h:mm tt");  
  167.         //            //DateTime thirdddate = DateTime.Parse(str3);  
  168.         //            string str5 = row["Payment Release Date"].ToString();  
  169.         //            string forthddate = Convert.ToDateTime(str5).ToString("yyyy-MM-dd h:mm tt");  
  170.         //            //DateTime forthddate = DateTime.Parse(str3);  
  171.         //            string str6 = row["Status"].ToString();  
  172.         //            string str7 = row["Cheque Date"].ToString();  
  173.         //            string str8 = row["Cheque No"].ToString();  
  174.         //            string str9 = row["Cheque Amount"].ToString();  
  175.         //            string str10 = row["TDS Amount"].ToString();  
  176.         //            int str6cn = 1;  
  177.         //            //str6 = 1;DateTime date = DateTime.ParseExact(strDate, "dd/mm/YYYY", null)  
  178.         //            //convert(varchar(20),GETDATE(),101)+ ' '+convert(varchar(20),GETDATE(),108)+ ' ' +right(convert(varchar(30),GETDATE(),109),0)  
  179.         //            //SqlCommand update = new SqlCommand("UPDATE dbo.Temp_Insert_Exel_TBL set AssociateSigndate='" + str2 + "',manager_sign_dt='" + str3 + "',submitted_to_acct_dt='" + str4 + "',payment_release_dt='" + str5 + "',bill_status='" + str6 + "',Chq_dt='" + str7 + "',Chq_no='" + str8 + "',Chq_amt='" + str9 + "',TDS_Amt='" + str10 + "' WHERE BillNo='" + str1 + "'", con1);  
  180.         //            SqlCommand update = new SqlCommand("UPDATE dbo.Temp_Insert_Exel_TBL_update set AssociateSigndate='" + firstdate + "',manager_sign_dt='" + seconddate + "',submitted_to_acct_dt='" + thirdddate + "',payment_release_dt='" + forthddate + "',bill_status='" + str6cn + "',Chq_dt=" + str7 + ",Chq_no='" + str8 + "',Chq_amt='" + str9 + "',TDS_Amt='" + str10 + "' WHERE BillNo='" + str1 + "'", con1);  
  181.         //            //SqlCommand update1 = new SqlCommand("IF NOT EXISTS(SELECT id_intrebare from Raspunsuri where id_intrebare=2) " + "Insert INTO Raspunsuri VALUES(@raspuns,@cnp,@data,2,@ip,@idsesiune) " + "else " + "UPDATE Raspunsuri SET raspuns=@raspuns,cod_numeric_personal=@cnp,data_raspuns=@data,id_intrebare=2,ip_user=@ip,id_sesiune=@idsesiune WHERE id_intrebare=2",con1);  
  182.         //            update.ExecuteNonQuery();  
  183.   
  184.   
  185.         //        }  
  186.         //        MSGLABLE.Text = "Record Upload Success Fully";  
  187.         //    }  
  188.         //    catch (Exception ex)  
  189.         //    {  
  190.         //        MSGLABLE.Text = ex.Message;  
  191.   
  192.         //    }  
  193.         //}  
  194.     }  
  195.     public void gridviesbind()  
  196.     {  
  197.         //MSGLABLE.Text = "These Recoed Are not uploded";  
  198.         string strConnection0 = Convert.ToString(ConfigurationManager.ConnectionStrings["AuditBilling"]);  
  199.         SqlConnection con0 = new SqlConnection(strConnection0);  
  200.         con0.Open();  
  201.         SqlCommand cmd0 = new SqlCommand("select * from dbo.Temp_Insert_Exel_TBL", con0);  
  202.         SqlDataAdapter da = new SqlDataAdapter(cmd0);  
  203.         DataSet ds0 = new DataSet();  
  204.         da.Fill(ds0);  
  205.         GridView1.DataSource = ds0;  
  206.         GridView1.DataBind();  
  207.         if (GridView1.Rows.Count == 0)  
  208.         {  
  209.             MSGLABLE.Text = "Record upload successfully";  
  210.         }  
  211.         else  
  212.         {  
  213.             MSGLABLE.Text = "These records Not Uploaded";  
  214.         }  
  215.   
  216.     }  
  217. }
Please Help me.......

Answers (4)