title: How to read a password protected Excel worksheet with OLEDB
body: <p>I have set a password on my excel sheet. To unlock the worksheet, I modified my OLEDB connection string, but it didn't work. I got an error that "the source contains no dataRows", which means that it couldn't read the data from the excel file.</p>
  
  <p>Before it was fine. What might be my problem?</p>
  
  <p>This is my code:    </p>
  
  <pre><code>public DataTable getExcelData(string fileName, string sheetName, ComboBox[] User_ComboBox)
  {
      this.m_comboBox = User_ComboBox;
  
    // connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" + fileName + "';Extended Properties= 'Excel 12.0 XML;HDR=No;IMEX=1'";
     connectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=" + fileName + ";Password=xyz;Extended Properties='Excel 8.0;HDR=YES'";
  
      string errorMessage = "";
      DataTable dt = new DataTable();
  
      try
      {
          string query = "SELECT * FROM [" + sheetName + "]";
          OleDbConnection con = new OleDbConnection(connectionString);
          OleDbDataAdapter dataAdapter = new OleDbDataAdapter(query, con);
          dataAdapter.Fill(dt);
      }
      catch (Exception exp)
      {
          // errorCode = ErrorDefinition.ERROR_OLEDBERROR;
          errorMessage = exp.Message;
      }
      return dt;
  }
  </code></pre>