Hi
I am connecting to an Excel workbook using the Microsoft.Jet.OLEDB in a C# windows application.
I create a connection string (OleDbConnection conn = new OleDbConnection(connString);) and manages to open the connection and retrieve data from the workbook into a OleDbDataReader.
At the end of the method I close the connection (using conn.Close()).
In the task manage however I see that EXCEL is stil an active process and I cannot open any of my Excel workbooks until I stop the EXCEL process in the Task Manager.
How will I stop the excel process insede my C# code?
Thanks
Kobus
Stopping Excel process inside C#?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Mike GoldRank #50 · 30.6K pointsPosted Jul 18, 2005, 7:04 PM EDT
it keeps reference counts of COM objects, and they aren't always decremented or incremented
properly. So what you have to do is forcefully kill the process. See code below:
using System.Diagnostics;
Process[] processes = System.Diagnostics.Process.GetProcessesByName("EXCEL");
foreach (Process p in processes){
p.Kill();
} -Mike G.
kobus_200014 pointsPosted Jul 18, 2005, 8:34 PM EDT
I shall try the code tonight.
Kobus