EXCEL.EXE process doesn't die after ADO.NET connection

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi everyone,

In a recent post I ask about a problem:
If I open a .NET application from EXCEL using SHELL function, when I close
EXCEL, the EXCEL.EXE process remain active and I must close it by Task
manager.

Today I have deepened the problem, and this is the new scenario:

1) I open "MyWorkbook.xsl" file with EXCEL;
2) In my worksheet I open a .NET application using SHELL function;
3) The opened .NET Application perform an ADO.NET Connection and a Query
from "MyWorkbook.xsl" workbook.
4) After perform the query, the connection and all the ADO.NET object
involved will be closed and disposed;
5) Now I close my .NET application;
6) If now I close Excel, the UI quit but the process EXCEL.EXE remain active
and I must close it by the Task Manager.

I suppose that the ADO.NET Connection, in some manner, remain opened or
locked and lock my workbook... So, how I can unlock the situation ?

Any ideas?

Thanks in advance.

Lorenzo Melato
 
Are you instantiating an instance of Excel from inside the .NET application?
If so you may have to close it explicitly before exiting the .NET
application.
 
Hello mklapp,

I've no instantiate any instance of EXCEL from inside the .NET application.

Lorenzo Melato
 
Try this, it launchs a Excel App., then open each Excel file, does something then
close each file and finally clean up Excel App.


public ParseXLS()
{
GC.Collect();

Excel.Application xlsApp = new Excel.Application();

xlsApp.Visible =false;

Excel.Workbook xlsWorkBook = null;

Excel.Worksheet xlsWorkSheet = null;

Excel.Range xslRange = null;


try
{

foreach(string f in Files) // An array of Excel file
{

xlsWorkBook = xlsApp.Workbooks.Open(f,

Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,Type.Missing,

Type.Missing,"\t",Type.Missing,Type.Missing,Type.Missing,Type.Missing);


xlsWorkSheet = (Excel.Worksheet)xlsApp.Worksheets.get_Item(1);


//Do Your Stuff here......

//Clean up Excel objects

xlsWorkBook.Close(false,f,Type.Missing);

System.Runtime.InteropServices.Marshal.ReleaseComObject(xslRange);

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWorkSheet);

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWorkBook);

}

}

catch(Exception x)

{

throw x;

}

finally

{

System.Runtime.InteropServices.Marshal.ReleaseComObject(xslRange);

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWorkSheet);

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsWorkBook);

xlsApp.Workbooks.Close();

xlsApp.Quit();

System.Runtime.InteropServices.Marshal.ReleaseComObject(xlsApp);

xlsApp = null;

GC.Collect();

}

}
 
Back
Top