locked
The remote procedure call failed. (Exception from HRESULT: 0x800706BE) from windows scheduled task RRS feed

  • Question

  • Following code is running fine when executed within command prompt running under service account but when tried under Windows scheduled task running under same service account on Windows Server 2008 R2 box, it hangs more than 1 hr and then errors out saying

    The remote procedure call failed. (Exception from HRESULT: 0x800706BE)STACKTRACE:   at System.RuntimeType.ForwardCallToInvokeMember(String memberName, BindingFlags flags, Object target, Int32[] aWrapperTypes, MessageData& msgData)
       at Microsoft.Office.Interop.Excel.Shapes.AddPicture(String Filename, MsoTriState LinkToFile, MsoTriState SaveWithDocument, Single Left, Single Top, Single Width, Single Height)

    Dim objExcel As Microsoft.Office.Interop.Excel.Application = Nothing
    Dim objWBook As Microsoft.Office.Interop.Excel.Workbook = Nothing
    Dim objDataHeader As Microsoft.Office.Interop.Excel.Range = Nothing
    Dim templateFileName As String

    objExcel = New Microsoft.Office.Interop.Excel.Application
    objExcel.DisplayAlerts = False

    If Not objExcel Is Nothing Then
    templateFileName = "C:\Test\ReportTemplate.xls"
    objWBook = objExcel.Workbooks.Open(templateFileName)
    objDataHeader = CType(objWBook.Sheets(1), Microsoft.Office.Interop.Excel.Worksheet).Range("A5:N35")
    objDataHeader.Worksheet.Shapes.AddPicture("C:\Test\temp.bmp", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, objDataHeader.Left, objDataHeader.Top, objDataHeader.Width, objDataHeader.Height)
    objWBook.SaveAs("C:\Test\output.xls", Microsoft.Office.Interop.Excel.XlWindowState.xlNormal)
    End If

    Friday, December 3, 2010 5:27 AM

Answers

  • Thanks Bruce, I appreciate your help. The issue got resolved for me by using clipboard to paste image into Excel worksheet.

    Tweaked code is as follows:

    Dim objExcel As Microsoft.Office.Interop.Excel.Application = Nothing
    Dim objWBook As Microsoft.Office.Interop.Excel.Workbook = Nothing
    Dim objDataHeader As Microsoft.Office.Interop.Excel.Range = Nothing
    Dim templateFileName As String
    Dim img As System.Drawing.Bitmap

    objExcel = New Microsoft.Office.Interop.Excel.Application
    objExcel.DisplayAlerts = False

    If Not objExcel Is Nothing Then
     templateFileName = "C:\Test\ReportTemplate.xls"
     objWBook = objExcel.Workbooks.Open(templateFileName)
     objDataHeader = CType(objWBook.Sheets(1), Microsoft.Office.Interop.Excel.Worksheet).Range("A5:N35")
     'objDataHeader.Worksheet.Shapes.AddPicture("C:\Test\temp.bmp", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, objDataHeader.Left, objDataHeader.Top, objDataHeader.Width, objDataHeader.Height)
     img = System.Drawing.Bitmap.FromFile("C:\Test\temp.bmp")
     System.Windows.Forms.Clipboard.SetImage(img)
     objDataHeader.Worksheet.Paste(objDataHeader, Type.Missing)
     img.Dispose()
     objWBook.SaveAs("C:\Test\output.xls", Microsoft.Office.Interop.Excel.XlWindowState.xlNormal)
    End If

    • Proposed as answer by Bruce Song Tuesday, December 7, 2010 2:17 AM
    • Marked as answer by Bruce Song Thursday, December 9, 2010 9:47 AM
    Monday, December 6, 2010 12:06 PM

All replies

  • Hi Sachit,

                Welcome to MSDN forum and I am glad to help with you.

                After reading your post, I knew your issue.

                Based on my analysis, the problem may due to the Windows Server 2008 R2 environment not Excel develop problem, I have collected some similar issue with it. You can take a look to see whether these can help you.

                Windows 2008R2 server Role error 0x800706BE

    http://social.technet.microsoft.com/Forums/en-US/winservermanager/thread/feae5af9-bb4e-463e-9ded-5f646aa9379c

                    Take a look at Tradle’s solution about the same issue.

                    http://social.msdn.microsoft.com/forums/en-US/vsto/thread/d6b183b1-4bd2-4eef-b0ad-1a2c3f17dafb

                Please let me know the result after you have tried the solutions.

    Best Regards,

    Bruce Song

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Monday, December 6, 2010 3:42 AM
  • Thanks Bruce, I appreciate your help. The issue got resolved for me by using clipboard to paste image into Excel worksheet.

    Tweaked code is as follows:

    Dim objExcel As Microsoft.Office.Interop.Excel.Application = Nothing
    Dim objWBook As Microsoft.Office.Interop.Excel.Workbook = Nothing
    Dim objDataHeader As Microsoft.Office.Interop.Excel.Range = Nothing
    Dim templateFileName As String
    Dim img As System.Drawing.Bitmap

    objExcel = New Microsoft.Office.Interop.Excel.Application
    objExcel.DisplayAlerts = False

    If Not objExcel Is Nothing Then
     templateFileName = "C:\Test\ReportTemplate.xls"
     objWBook = objExcel.Workbooks.Open(templateFileName)
     objDataHeader = CType(objWBook.Sheets(1), Microsoft.Office.Interop.Excel.Worksheet).Range("A5:N35")
     'objDataHeader.Worksheet.Shapes.AddPicture("C:\Test\temp.bmp", Microsoft.Office.Core.MsoTriState.msoFalse, Microsoft.Office.Core.MsoTriState.msoCTrue, objDataHeader.Left, objDataHeader.Top, objDataHeader.Width, objDataHeader.Height)
     img = System.Drawing.Bitmap.FromFile("C:\Test\temp.bmp")
     System.Windows.Forms.Clipboard.SetImage(img)
     objDataHeader.Worksheet.Paste(objDataHeader, Type.Missing)
     img.Dispose()
     objWBook.SaveAs("C:\Test\output.xls", Microsoft.Office.Interop.Excel.XlWindowState.xlNormal)
    End If

    • Proposed as answer by Bruce Song Tuesday, December 7, 2010 2:17 AM
    • Marked as answer by Bruce Song Thursday, December 9, 2010 9:47 AM
    Monday, December 6, 2010 12:06 PM
  • Hi Sachit,

           Sorry for that my suggestion didn't help you.

           I am very glad that you have resolved your issue with your rich experience and strong skills, and share your solution with us.

           You are welcome. Wish you a nice day.

    Best Regards,

    Bruce Song

     


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    Tuesday, December 7, 2010 2:16 AM