Hi All,

before I seperated my web app out into a WCF Service Library running under windows services, I had a reference to Microsoft.Office.Interop.Excel.

Originally I didn't have this as I was using ADO.NET to reference the spreadsheets, but thne some files were not all saved as workbooks, so I needed to introduce a test and then re-save the worksheets as workbooks requiring the office reference. This worked fine in my standard web app, but now that it has become part of my wcf Service I receive the following error:



Code:
Retrieving the COM class factory for component with CLSID {00024500-0000-0000-C000-000000000046} failed due to the following error: 80070005 Access is denied. (Exception from HRESULT: 0x80070005 (E_ACCESSDENIED)).
also this is the code in my WCF application that causes the error:



Code:
private OleDbConnection conn(String Source)
        {

            //before opening make sure the excel sheet has been saved as a workbook!!!! this one got me as some are sent as worksheets causing strange failures.
            Microsoft.Office.Interop.Excel.Application ExcelApp = new Microsoft.Office.Interop.Excel.Application();
            ExcelApp.DisplayAlerts = false;
            try
            {
                Microsoft.Office.Interop.Excel.Workbook WB = ExcelApp.Workbooks.Open(@Source);
                WB.SaveAs(@Source, Microsoft.Office.Interop.Excel.XlFileFormat.xlWorkbookNormal, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Microsoft.Office.Interop.Excel.XlSaveAsAccessMode.xlExclusive, Type.Missing, Type.Missing, Type.Missing, Type.Missing, Type.Missing);
                WB.Close(true, @Source, false);
                ExcelApp.Quit();

                OleDbConnection localConn = new OleDbConnection("provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + @Source + ";Extended Properties = Excel 8.0;");

                localConn.Open();
                return localConn;
            }
            catch (Exception ex)
            {
                ExcelApp.Quit(); //something went wrong, at least attempt to clear Excel from Local Memeory.
                throw ex;
            }
        }
At the moment All of these are running locally, as I'm trying to do an end-to -end test before allowing testers use of the app.