Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Visual Basic > VB 2010 > Visual Basic 2010 General Discussion
|
Visual Basic 2010 General Discussion For any discussions about Visual Basic 2010 topics which aren't related to a specific Wrox book
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Visual Basic 2010 General Discussion section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 15th, 2011, 03:51 PM
Registered User
 
Join Date: Jul 2011
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Post Office Interop & writing to disk using server 2008 scheduler

Hello,

Brief Summary:
I am having (i think permission) issues saving excel files from a console application i wrote in vb.net 2010 (32 bit, .net 3.5) using the office interop library (12) for excel that is triggered by a windows task scheduler event on a 64bit Windows server 2008R2 OS.
  • my error is when i run it from the windows task scheduler, i get: Exception from HRESULT: 0x800A03EC
  • the program works fine when i run it manually from the desktop on 2008 as the same user.
  • the program works fine from the scheduler if i run it in 32bit XP Pro
  • I am positive that the user the scheduler runs as has full access to the intended filepath.

Question:
I am guessing it is a permissions thing but so far 2 hours worth of googling and fidgeting with folder/file permissions hasn't helped. Does anyone have any ideas on what may be going on here? Do i need to register my program in windows somewhere so it knows it is trusted?

The Code. I take a dataset that i filled from a database and try to write it to an excel.
Code:
Imports Microsoft.Office.Interop.Excel
Private Sub CreateExcel(ByVal objDataset As DataSet, ByVal wy As String, ByVal objSite As CEWAGDSiteClass.SiteLocation, ByVal objConnection As System.Data.OleDb.OleDbConnection)

        ' this is a sub that kills left over latent excel processes
        KillProcesses()


        Dim xlApp As Microsoft.Office.Interop.Excel.Application
        Dim xlWorkBook As Microsoft.Office.Interop.Excel.Workbook
        Dim xlWorkSheet As Microsoft.Office.Interop.Excel.Worksheet
        Dim misValue As Object = System.Reflection.Missing.Value


        xlApp = New Microsoft.Office.Interop.Excel.Application
        xlWorkBook = xlApp.Workbooks.Add(misValue)
        xlWorkSheet = xlWorkBook.Sheets("sheet1")

        ' add labels
        xlWorkSheet.Cells(2, 3) = "Date"
        xlWorkSheet.Cells(2, 4) = "Water Stage (ft)"
        xlWorkSheet.Cells(2, 5) = "Water Temp (C)"
        Try
            WriteLog("Attempting to create excel for Site " & objSite.SiteName & "-" & objSite.CEMAR_Name)
            'add data
            For i = 0 To objDataset.Tables(0).Rows.Count - 1
                xlWorkSheet.Cells(i + 3, 3) = objDataset.Tables(0).Rows(i).Item(0)
                xlWorkSheet.Cells(i + 3, 4) = objDataset.Tables(0).Rows(i).Item(1)
                xlWorkSheet.Cells(i + 3, 5) = objDataset.Tables(0).Rows(i).Item(2)
            Next
            '   MsgBox("populated")
            WriteLog("Created Excel For Site " & objSite.SiteName & "-" & objSite.CEMAR_Name)
        Catch ex As Exception
            MsgBox(ex.Message.ToString)
        End Try


        Try
            xlWorkSheet.SaveAs("\\sockeye\Shares\CEMAR_Running_Stage_Excels\WY" & wy & "\" & objSite.SiteName &
                                     "-" & objSite.CEMAR_Name & "WY" & wy & ".xlsx")
          
            xlWorkBook.Close()
            xlApp.Quit()

            releaseObject(xlApp)
            releaseObject(xlWorkBook)
            releaseObject(xlWorkSheet)
        Catch ex As Exception
            WriteLog("Error saving \\sockeye\Shares\CEMAR_Running_Stage_Excels\WY" & wy & "\" & objSite.SiteName &
                                      "-" & objSite.CEMAR_Name & "WY" & wy & ".xlsx" & vbNewLine & ex.Message.ToString)
            'WriteLog("Error saving D:\Shares\CEMAR_Running_Stage_Excels\WY" & wy & "\" & objSite.SiteName &
            '                        "-" & objSite.CEMAR_Name & "WY" & wy & ".xlsx" & vbNewLine & ex.Message.ToString)

            email_error(("Error saving Site " & objSite.SiteName & "-" & objSite.CEMAR_Name) & vbNewLine & ex.Message.ToString, "Daily Stage Data Excel Population Failed")
            ' Close the DB connection since the program is going to shut down
            objConnection.Close()
            WriteLog("-------------------" & " Program Ended On Error " & "-------------------" & vbNewLine & " ")
            End
        End Try

    End Sub
    Private Sub releaseObject(ByVal obj As Object)
        Try
            System.Runtime.InteropServices.Marshal.ReleaseComObject(obj)
            obj = Nothing
        Catch ex As Exception
            obj = Nothing
        Finally
            GC.Collect()
        End Try
    End Sub





Similar Threads
Thread Thread Starter Forum Replies Last Post
Anyone tested the HR appl code on VWD Express Edition & SQL server Exp 2008 seemashah BOOK: ASP.NET 3.5 Enterprise Application Development with Visual Studio 2008: Problem Design Solutio 0 July 27th, 2010 02:43 PM
Help With Visual Studio 2008 & SQL Server 2005 Express Rambo Visual Studio 2008 3 December 21st, 2009 12:08 PM
Insert Table using office interop Power Point yuenli C# 2005 0 September 2nd, 2007 04:55 AM
Issue with Office Interop karveajit .NET Framework 1.x 1 November 28th, 2005 06:56 AM
writing to the disk file incase of database devt. antonkingdee C++ Programming 0 July 18th, 2003 06:39 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.