Question : SSIS Script task Excel object reference release

Hi,
I am writing an SSIS package that checks a specific folder for Excel files.  Files are dropped into this folder periodically for data updates to our SQL Server.  The files are always named differently, as are the worksheets.  I have the Data Flow tasks to upload the data to SQLS.  

I am writing a Script task in SSIS (VB.NET) to change the Excel file and worksheet names to a standard name (such as Data.xls, DataSheet) for use in the Data Flow tasks.

I have a reference and Imports directive to the Microsoft.Office.Interop.Excel object.

I declare a variable of the MS.Office.Interop.Excel type and access the Excel file.

When I'm finished with the object, how do I destroy it?  There are still references to Excel.exe in the Task Manager, which are creaeted when executing the task.

 I have tried the following to no avail:

excel.dispose()
set excel =nothing '(and old VB 6 technique)

I've also tried calling the
GC.Collect()
GC.WaitForPendingFinalizers() methods, which have not worked.  


Thanks in advance
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
Imports System
Imports System.Data
Imports System.Math
Imports Microsoft.SqlServer.Dts.Runtime
Imports System.ComponentModel
Imports System.IO
Imports Microsoft.Office.Interop.Excel
 
Public Class ScriptMain
 
    Public Shared Sub Main()
        
        Dim storefile As Directory
        Dim directory As String
        Dim files As String()
        Dim file As String
        Dim FileName As String, FolderName As String
 
 
        FolderName = "\\acct.upmchs.net\psd\ccm\main\CCM_Report_Data\billing_Inbound\"
 
        files = storefile.GetFiles(FolderName, "*.xls")
        For Each file In files
            
            Dim excel As New Microsoft.Office.Interop.Excel.Application
            Dim Book As Workbook
 
            Book = excel.Workbooks.Open(file)
            Book.SaveAs(FolderName & "data.xls")
            'I'll add code to change the worksheet name at a later date
            Book.Close()
        Next file
 
        Dts.TaskResult = Dts.Results.Success
    End Sub
 
End Class

Answer : SSIS Script task Excel object reference release

Its not clear from your post: have you tried

Set excel = nothing
System.GC.Collect

together?

Have you tried

Set Book = Nothing

also?

Does this help (just reiterating what I said above)


http://books.google.com/books?id=yvV1Bl5fx_cC&pg=PA948&lpg=PA948&dq=.Net+garbage+collector+excel&source=bl&ots=vwluakvYyj&sig=QA0uDrlHYD1czkuuWN87WdQKj5c&hl=en&ei=cFO7SufaHciIkQW_l5W1DQ&sa=X&oi=book_result&ct=result&resnum=3#v=onepage&q=&f=false

Random Solutions  
 
programming4us programming4us