executing SSIS package(import data from Excel to sqlserver) in C# creates excel proess in task manager .

Mohsin Raza 21 Reputation points
2022-12-06T14:07:10.357+00:00

Hi,

I develop a c#program that execute SSIS package on button click and it import data from excel to sqlserver. It works fine first time and when i tried to run again. It shows error that excel fil is already open.

To run the program again I made "endtask" the "excel processes" in "Task manager" .

How can this problem be solved? .

with regards.

Microsoft 365 and Office | Development | Other
Developer technologies | C#
{count} votes

2 answers

Sort by: Most helpful
  1. Oskar Shon 866 Reputation points
    2022-12-14T10:02:42.227+00:00

    Yes. you should add to your code ReleaseObject procedure because close file is not enough.
    In VB I use code looks like:

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

    and you can use it:

    ReleaseObject(wks)  
    wkb.Close(False) ' or True if you save it once with name'  
    ReleaseObject(wkb)  
    

    Regards

    1 person found this answer helpful.
    0 comments No comments

  2. Rick Kirkham 281 Reputation points Microsoft Employee
    2022-12-06T22:49:59.537+00:00

    You have tagged this office-addins-dev, but if I understand correctly, you are not making an Office Add-in. Is that correct?

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.