tags:

views:

17

answers:

0

Really odd that I'd get an oledbexception but turns out that the file's handle is still with the original file. I've been searching through google and keep finding the same problem but no solutions.

Connection String:

"Provider=Microsoft.Jet.OLEDB.4.0;" +
"Data Source=" + filePath + ";" +
 "Extended Properties=Excel 8.0;";

Note that it works on every other file except a particular excel file.

Exception:

System.Data.OleDb.OleDbException: No error information available: E_UNEXPECTED(0x8000FFFF).

And then I have exception handling like this:

OleDbConnection _connection = new OleDbConnection(connString); List _tableNames = new List();

        try
        {
            // Error Handle
            _connection.Open();

            // Gets the worksheet names
            DataTable _excelSchema = _connection.GetSchema("Tables");
            foreach (DataRow _excelSchemaRow in _excelSchema.Select("NOT(TABLE_NAME LIKE '*_')"))
            {
                _tableNames.Add((string)_excelSchemaRow["TABLE_NAME"]);
            }
        }
        catch (OleDbException ex)
        {
            LogUtil.Error("Could not get Workbook Worksheet names.");
            LogUtil.Error(ex);
            throw ex;
        }
        finally
        {
            _connection.Close();
            _connection.Dispose();
        }

Has anyone else encountered this behavior? The error gets thrown when I open the connection. And I'm not sure how to handle an error that keeps the handle on the file I'm supposed to process. It sort of freezes everything in place.