title: Error in excel = new Microsoft.Office.Interop.Excel.ApplicationClass();" when hosted in server machine..[dcomcnfg]
body: <p>The following is the code which thows error when hosted in Server PC.</p>
  
  <pre><code>try
  {
      //Variable Declarations
      Microsoft.Office.Interop.Excel._Workbook oWB;
      Microsoft.Office.Interop.Excel.Application oXL = null;
  
      Microsoft.Office.Interop.Excel.Workbook workbook;
      Microsoft.Office.Interop.Excel.Worksheet NwSheet = null;
      Microsoft.Office.Interop.Excel.Worksheet NwSheetSummary;
      Microsoft.Office.Interop.Excel.Worksheet NwSheetIndividualTotal;
      Microsoft.Office.Interop.Excel.Range ShtRange;
      Microsoft.Office.Interop.Excel.Sheets sheets;
  
      Microsoft.Office.Interop.Excel.ApplicationClass excel = new Microsoft.Office.Interop.Excel.ApplicationClass();
  
      excel.Workbooks.Add(System.Reflection.Missing.Value);
  
      excel.Quit();
      excel = null;
  
      //Opening Excel file(myData.xlsx)
      workbook = excel.Workbooks.Open(System.Web.HttpContext.Current.Server.MapPath("~/Template/Template.xlsx"), Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value, Missing.Value);
      sheets = workbook.Worksheets;
      foreach (Worksheet ws in sheets)
      {
          if (ws.Index == 5)
              NwSheet = ws;
          if (ws.Index == 1)
              NwSheetSummary = ws;
          if (ws.Index == 4)
              NwSheetIndividualTotal = ws;
      }
  
      //Reading Excel file.
      //Creating datatable to read the containt of the Sheet in File.
      System.Data.DataTable dt = export.Tables[0];
  
      int rowCount = 8;
  
      if (dt.Columns.Contains("RowID"))
          dt.Columns.Remove("RowID");
      if (dt.Columns.Contains("Week"))
          dt.Columns.Remove("Week");
      if (dt.Columns.Contains("Year"))
          dt.Columns.Remove("Year");
      foreach (DataRow dr in dt.Rows)
      {
  
          rowCount += 1;
          for (int i = 1; i &lt; dt.Columns.Count + 1; i++)
          {
              // Add the header the first time through 
              if (rowCount == 8)
              {
                  //NwSheet.Cells[1, i] = dt.Columns[i - 1].ColumnName;
              }
              NwSheet.Cells[rowCount, i] = dr[i - 1].ToString();
          }
      }
  
      for (int count = 0; count &lt;= dt.Rows.Count; count++)
      {
          // NwSheet.get_Range("A9", Missing.Value).Value2 = dt.Rows[count]["SlNo"].ToString();
  
  
      }
      workbook.RefreshAll();
      String path = Convert.ToString(ConfigurationManager.AppSettings["DefaultPath"]);
  
      CreateFileOrFolder(workbook, week);
      NwSheet = null;
      ShtRange = null;
      workbook.Close(Missing.Value, Missing.Value, Missing.Value);
      workbook = null;
      oXL.Quit();
      excel.Quit();
      //appExl.Quit();
      status = true;
  }
  </code></pre>
  
  <p>Now it run's fine in my local PC which has <code>Interop Excel 12.0</code> but not when hosted in server machine which has same <code>12.0</code>.</p>
  
  <p>the error received is </p>
  
  <blockquote>
    <p>Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005.</p>
  </blockquote>
  
  <p>After googling out for the error I had gone through other forums and they had mentioned to <code>give rights to Network Services to Microsoft Excel Application in dcomcnfg</code>. I did the same thing but its of no use. </p>
  
  <p>It didnt worked out and I got the same error.
  Like :- 
  <a href="http://blog.crowe.co.nz/archive/2006/03/02/589.aspx" rel="nofollow">Configuration of dcomcnfge</a> </p>
  
  <p>Which Say's:-</p>
  
  <blockquote>
    <p>Goto Control-Panel --> Administrative tools-->Component Services -->computers --> myComputer -->DCOM Config --> Microsoft Excel Application. --> Right click to get properties dialog. Goto Security tab and customize permissions accordingly.</p>
  </blockquote>
  
  <p>I have tried giving all possible right's but still the error persist's.!!</p>
  
  <p>Please help..</p>