Results 1 to 3 of 3

Thread: [RESOLVED] Office interop errors in WCF Service

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Resolved [RESOLVED] Office interop errors in WCF Service

    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.

  2. #2

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: Office interop errors in WCF Service

    Ok,

    I found another link suggesting that I need to give access to the office objects via DCOM.

    http://j-integra.intrinsyc.com/suppo...oteaccess.html


    Following this, I have now got rid of the COM Error, however now when my app tries to access the Excel file I receive an error : Cannot Access read-only document 'mySpreadsheet.xls'.

    right mouse click the document and the read only property isn't set????

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Feb 2000
    Location
    Dunmow,Essex,England
    Posts
    898

    Re: Office interop errors in WCF Service

    Doh!!! I needed to give Network Service User access rights to the directory that the files reside in.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width