title: Read Excel file with OleDB c#, when it is used by other process
body: <p>I am trying to read an excel file every 2 seconds, This file is getting updated by other RTD application. </p>
  
  <p>I am able to read this file by Oledb connection, but problem comes when i am trying to read it every 2 seconds. Out of 10 attempts it is able to read 4-5 times only and at other attempts ,it throws exception. </p>
  
  <p><strong>Connection String</strong></p>
  
  <pre><code>Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\nids\shes.xlsm;Extended Properties="Excel 12.0 Macro;HDR=Yes;IMEX=1"
  </code></pre>
  
  <p><strong>Code</strong></p>
  
  <pre><code>//opening connection to excel file
  
  using (OleDbConnection connection = new OleDbConnection(constr))//constr = connection string
  {
      try
      {  
          connection.Open();
          isconopen = true;
      }
      catch
      {
          dispatcherTimer2.Start();
  
          connection.Close();
          isconopen = false;
      }
  
      // If connection is ok , then query sheet  
      if (isconopen == true)
      {
          strcon = "SELECT * FROM [" + dsheet + "]";
  
          using (OleDbDataAdapter adapter = new OleDbDataAdapter(strcon, connection))
          {
  
              try
              {
  
  
                  adapter.Fill(result);
                  isread = true;
                  adapter.Dispose();
  
                  connection.Close();
              }
              catch 
              {
  
                  isread = false;
                  dispatcherTimer2.Start();
  
                  adapter.Dispose();
                  connection.Close();
  
              }
  
          }
       }
  
      //if able to retrieve data then call some other function 
      if (isread == true)
      {
          converToCSV(0);// for further processing
      }
  </code></pre>
  
  <p>Please help me , i am trying this from last 1 month. Please please please please help me out</p>