title: OleDbDataReader object cannot read the file
body: <p>I have developed a functionality, where I import Excel sheet to the table. But when I upload the file and click on the button to import. The code doesn't works and gives me the below mentioned error. I tried with DataAdapter but that was also not working. Please see the error below:-</p>
  
  <blockquote>
    <p>The Microsoft Office Access database engine could not find the object
    '<code>TableName</code>'.  Make sure the object exists and that you spell its
    name and the path name correctly.</p>
  </blockquote>
  
  <p>Also, Please see the code for your reference:-</p>
  
  <pre><code> private void ImporttoSQL(string sPath)
  {  
      string sSourceConstr1 = string.Format(@"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\AgentList.xls; Extended Properties=""Excel 8.0;HDR=YES;""", sPath);
      string sSourceConstr = string.Format(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0};Extended Properties=""Excel 12.0 Xml;HDR=YES;""", sPath);
      OleDbConnection sSourceConnection = new OleDbConnection(sSourceConstr);
      using (sSourceConnection)
      {
          string sql = string.Format("Select [Merchant_Name],[Store_Name],[Store_Address],[City] FROM [MerchantTempDetail]", "Sheet1$");
          OleDbCommand command = new OleDbCommand(sql, sSourceConnection);
          sSourceConnection.Open();
          conn.Open();
          using (OleDbDataReader dr = command.ExecuteReader())
          {
              using (SqlBulkCopy bulkCopy = new SqlBulkCopy(conn))
              {
                  bulkCopy.DestinationTableName = "MerchantTempDetail";
                  //You can mannualy set the column mapping by the following way.
                  //  bulkCopy.ColumnMappings.Add("Mini_Category_Id", "Mini_Category_Id");
                  //bulkCopy.ColumnMappings.Add("CategoryId", "CategoryId");
                  bulkCopy.ColumnMappings.Add("Merchant_Name", "Merchant_Name");
                  bulkCopy.ColumnMappings.Add("Store_Name", "Store_Name");
                  bulkCopy.ColumnMappings.Add("Store_Address", "Store_Address");
                  bulkCopy.ColumnMappings.Add("City", "City");
                  bulkCopy.WriteToServer(dr);
              }
          }
      }
  }
  </code></pre>
  
  <p>Edited code :-</p>
  
  <pre><code> public static void ExcelToSqlServerBulkCopy()
  {
      // Connection String to Excel Workbook
      // Jet4
      string excelConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0; Data Source=AgentList.xls; Extended Properties=""Excel 8.0;HDR=YES;""";
      // Ace Ole db 12
      string excelAceOleDb12ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=AgentList.xls;Extended Properties=""Excel 8.0;HDR=YES;""";
  
      // Create Connection to Excel Workbook
      using (OleDbConnection connection = new OleDbConnection(excelAceOleDb12ConnectionString))
      {
          OleDbCommand command = new OleDbCommand("Select [Merchant_Name],[Store_Name],[Store_Address],[City] FROM [Sheet1$]", connection);
          // open excel
          connection.Open();
          // Create DbDataReader to Data Worksheet
          using (DbDataReader dr = command.ExecuteReader())
          {
              // SQL Server Connection String
              string sqlConnectionString = ConfigurationManager.ConnectionStrings["DefaultSQLConnectionString"].ConnectionString;
              // Bulk Copy to SQL Server
              using (SqlBulkCopy bulkCopy = new SqlBulkCopy(sqlConnectionString))
              {
                  bulkCopy.DestinationTableName = "MerchantTempDetail";
                  bulkCopy.WriteToServer(dr);
              }
          }
      }
  }
  
  protected void btnImport_Click(object sender, EventArgs e)
  {
      if (FileUpload1.HasFile)
      {
          string sPath = Server.MapPath(FileUpload1.FileName);
          FileUpload1.SaveAs(sPath);
  
          ExcelToSqlServerBulkCopy();
      }
  }
  </code></pre>