title: How to retrieve data from Excel file using OleDbConnection
body: <p>the thing is that I need to select only 2 columns from the data in Excel, so i went on using sql for retrieving the data from the Excel file. But this time i keep getting "failed to create file" error and this happens when i try to open my connection. Why is it trying to create a file ?</p>
  
  <p>my code:</p>
  
  <pre><code>public void ReadExcelFile()
  {
      string connectionString = string.Format(ConfigurationManager.ConnectionStrings["ExcelConnection"].ConnectionString.Replace("'", "\""), "@C:/Temp/Copy.xlsx");
      using (OleDbConnection connection = new OleDbConnection(connectionString))
      {
          try
          {
              connection.Open();
              string sqlCmd = "SELECT  * FROM [Ark1$]";
              using (OleDbCommand command = new OleDbCommand(sqlCmd, connection))
              {
                  command.CommandType = System.Data.CommandType.Text;
                  using (OleDbDataReader reader = command.ExecuteReader())
                  {
                      while (reader.Read())
                      {
                          Console.WriteLine(reader.ToString());
                      }
                  }
              }
  
          }
          catch (Exception exception)
          {
              Console.WriteLine("ERROR in ReadExcelFile() method. Error Message : " + exception.Message);
          }
      }
  }
  </code></pre>
  
  <p>can anyone help me with this ?</p>