Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 917253
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T18:10:55+00:00 2026-05-15T18:10:55+00:00

I’m trying to read an excel file using an OleDb Reader, I couldn’t debug

  • 0

I’m trying to read an excel file using an OleDb Reader, I couldn’t debug the code because this error only comes out on a production server. It really doesn’t make sense to me, could anyone help me?

From the logs the error comes out as:

System.Data.OleDb.OleDbException: Object invalid or no longer set.
at System.Data.OleDb.OleDbConnectionInternal.ProcessResults(OleDbHResult hr)
at System.Data.OleDb.OleDbConnectionInternal.GetSchemaRowset(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbConnection.GetOleDbSchemaTable(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbMetaDataFactory.PrepareCollection(String collectionName, String[] restrictions, DbConnection connection)
at System.Data.ProviderBase.DbMetaDataFactory.GetSchema(DbConnection connection, String collectionName, String[] restrictions)
at System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)
at System.Data.OleDb.OleDbConnection.GetSchema(String collectionName, String[] restrictionValues)
at System.Data.OleDb.OleDbConnection.GetSchema(String collectionName)

Also, a little while before this error appeared, I had a

System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
at System.Data.Common.UnsafeNativeMethods.IDBSchemaRowset.GetRowset(IntPtr pUnkOuter, Guid& rguidSchema, Int32 cRestrictions, Object[] rgRestrictions, Guid& riid, Int32 cPropertySets, IntPtr rgPropertySets, IRowset& ppRowset)
at System.Data.OleDb.OleDbConnectionInternal.GetSchemaRowset(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbConnection.GetOleDbSchemaTable(Guid schema, Object[] restrictions)
at System.Data.OleDb.OleDbMetaDataFactory.PrepareCollection(String collectionName, String[] restrictions, DbConnection connection)
at System.Data.ProviderBase.DbMetaDataFactory.GetSchema(DbConnection connection, String collectionName, String[] restrictions)
at System.Data.ProviderBase.DbConnectionInternal.GetSchema(DbConnectionFactory factory, DbConnectionPoolGroup poolGroup, DbConnection outerConnection, String collectionName, String[] restrictions)
at System.Data.OleDb.OleDbConnection.GetSchema(String collectionName, String[] restrictionValues)
at System.Data.OleDb.OleDbConnection.GetSchema(String collectionName)

exception as well. I don’t know if they are related. Can anyone point me in the right direction?

The code I’m using to read the file is

            DateTime start = DateTime.Now;
            IEnumerable<string> worksheetNames = GetWorkbookWorksheetNames( connString );
            using ( OleDbConnection connection = new OleDbConnection( connString ) )
            {
                connection.Open();
                foreach ( string worksheetName in worksheetNames )
                {
                    using ( OleDbCommand command = 
                        new OleDbCommand( "SELECT * FROM [" + worksheetName + "]", connection ) )
                    {
                        TEntity entity;
                        using ( OleDbDataReader dataReader = command.ExecuteReader() )
                        {
                            while ( dataReader.Read() )
                            {
                                entity = GetDataFromDataTable( dataReader );

                                if ( entity != null )
                                {
                                    entityList.Add( entity );
                                }
                            }
                        }
                    }
                }
                connection.Close();

GetWorkbookWorksheetNames contains

private IEnumerable<string> GetWorkbookWorksheetNames( string connString )
    {
        LogUtil.Info( "Getting workbook worksheet names" );
        OleDbConnection _connection = new OleDbConnection( connString );
        List<string> _tableNames = new List<string>();
        try
        {
            // Error Handle
            _connection.Open();
            // Gets the worksheet names
            DataTable _excelSchema = _connection.GetSchema( "Tables" );

            if ( _excelSchema.Rows.Count < 1 )
            {
                throw new FormatException( "The file is in an invalid format. No worksheets were found." );
            }

            foreach ( DataRow _excelSchemaRow in _excelSchema.Rows )
            {
                _tableNames.Add( Regex.Replace( (string)_excelSchemaRow["TABLE_NAME"], "_$", "" ) );
            }
        }
        catch ( OleDbException ex )
        {
            LogUtil.Error( "Could not get Workbook Worksheet names." );
            LogUtil.Error( ex );
            throw ex;
        }
        finally
        {
            _connection.Close();
        }
        return _tableNames;
    }

And I’m sure the error doesn’t get to GetDataFromDataTable()

EDIT: The connection string I’m using is:

        string connString = "Provider=Microsoft.Jet.OLEDB.4.0;" +
                        "Data Source=" + filePath + ";" +
                        "Extended Properties=\"Excel 8.0;HDR=No;IMEX=1\";";

I also found out, further back in my logs, another error that made no sense to me at all. I didn’t notice this before but it took place just before the AccessViolationException.

No error message available, result code: E_UNEXPECTED(0x8000FFFF).
at System.Data.OleDb.OleDbConnectionInternal..ctor(OleDbConnectionString constr, OleDbConnection connection)
at System.Data.OleDb.OleDbConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.OleDb.OleDbConnection.Open()
at REMEC.Library.WatcherServiceCommon.ExcelParserService`1.GetWorkbookWorksheetNames(String connString) in

And while simulating this error under a test, the thread never stops, making me assume that said error does not actually close the connection even after explicitly closing it on my finally clause.

Sorry for the long blocks of code/text

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T18:10:56+00:00Added an answer on May 15, 2026 at 6:10 pm

    Possibly – ConnStr Value Problem;
    Try this:

    private String[] GetExcelSheetNames(string excelFile)
    {
    OleDbConnection objConn = null;
    System.Data.DataTable dt = null;

      try
      {
        // Connection String. Change the excel file to the file you
        // will search.
    
        String connString = "Provider=Microsoft.Jet.OLEDB.4.0;" + 
            "Data Source=" + excelFile + ";Extended Properties=Excel 8.0;";
        // Create connection object by using the preceding connection string.
    
        objConn = new OleDbConnection(connString);
        // Open connection with the database.
    
        objConn.Open();
    
        // Get the data table containg the schema guid.    
        dt = objConn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, null);
    
        if(dt == null)
        {
          return null;
        }
    
        String[] excelSheets = new String[dt.Rows.Count];
        int i = 0;
    
        // Add the sheet name to the string array.
    
        foreach(DataRow row in dt.Rows)
        {
          excelSheets[i] = row["TABLE_NAME"].ToString();
          i++;
        }
    
        // Loop through all of the sheets if you want too...
    
        for(int j=0; j < excelSheets.Length; j++)
        {
          // Query each excel sheet.
    
        }
    
        return excelSheets;
      }
      catch(Exception ex)
      {
        return null;
      }
      finally
      {
        // Clean up.
    
        if(objConn != null)
        {
          objConn.Close();
          objConn.Dispose();
        }
        if(dt != null)
        {
          dt.Dispose();
        }
      }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I have this code to decode numeric html entities to the UTF8 equivalent character.
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.