EXCEL.EXE process closes immeditately when using COM Interop
I'm using COM Interop to access Excel from a Centura Team Developer program and the EXCEL.EXE process exits immediately after calling Create in my Application. All later calls throw exception because Excel is not open anymore.
What could be the reason for this behaviour?
Because you did not free all Variable ref to COM Object. You need to set the Variable ref to COM Object as null.
OleDbConnection OleConn = new OleDbConnection(strConn);
OleConn.Open();
String sql = "SELECT * FROM [Sheet1$]";
OleDbDataAdapter OleDaExcel = new OleDbDataAdapter(sql, OleConn);
DataSet OleDsExcle = new DataSet();
OleDaExcel.Fill(OleDsExcle, "Sheet1");
OleConn.Close();
OleConn = null;
like OleConn, you need to free all Variable ref to COM Object.
链接地址: http://www.djcxy.com/p/35682.html上一篇: 从C#读取Excel文件