InvalidComObjectException

Posts   
 
    
loren
User
Posts: 14
Joined: 29-Jul-2006
# Posted on: 19-Jul-2008 11:47:13   

I'm trying to work on a project from about a year ago. I am working on a new workstation and my previous workstation is not available so I wanted to regenerate it with the updated LLBLGen engine. The project was originally developed in LLBLGen v2.0 to and is now generated in v2.6.

I consistently get the message "InvalidComObjectException: COM object that has been separated from its underlying RCW cannot be used" when I try to .Fill() any TypedList with a filter applied as follows:

IPredicateExpression filter = new PredicateExpression();
filter.Add(Company.LlblGen.HelperClasses.EmployeeFields.EmployeeId > 0);
EmployeeTypedList list = new EmployeeTypedList()
list.Fill(0, null, false, filter);

The query works as expected if I remove the filter by replacing the last line with:

list.Fill(0, null, false, null);

The filter also works fine if I apply it to an EmployeeCollection so there's not a problem with the general configuration of the framework or database connectivity. The problem only appears to affect TypedLists and all of the TypedLists in my project generate the same error when a filter is applied during .Fill().

I checked the build log, the forums, Google, and Microsoft, but can't seem to find anything obvious. Please help... I'm stumped.

Here are the technical details...

  • LLBLGen version/release: v2.6 Final, June 6, 2008
  • SD.LLBLGen.Pro.ORMSupportClasses.NET20.dll: 2.6.08.0624
  • Template: Self-Servicing, General2005 Presets
  • Database: Microsoft Access 2003
  • Connection String: "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Project\Database\Main.mdb;User Id=;Password=;Jet OLEDB:System Database=;Jet OLEDB:Database password="
  • Exception: System.Runtime.InteropServices.InvalidComObjectException STACK TRACE:
at System.Data.Common.UnsafeNativeMethods.IAccessor.ReleaseAccessor(IntPtr hAccessor, Int32& pcRefCount)
   at System.Data.OleDb.RowBinding.Dispose()
   at System.Data.OleDb.Bindings.Dispose()
   at System.Data.OleDb.OleDbCommand.CloseInternal()
   at System.Data.OleDb.OleDbCommand.ResetConnection()
   at System.Data.OleDb.OleDbCommand.Dispose(Boolean disposing)
   at System.ComponentModel.Component.Dispose()
   at SD.LLBLGen.Pro.ORMSupportClasses.Query.Dispose(Boolean isDisposing)
   at SD.LLBLGen.Pro.ORMSupportClasses.Query.Dispose()
   at SD.LLBLGen.Pro.ORMSupportClasses.DaoBase.PerformGetMultiAsDataTableAction(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize)
   at Pesco.LlblGen.DaoClasses.TypedListDAO.GetMultiAsDataTable(IEntityFields fieldsToReturn, DataTable tableToFill, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPredicate selectFilter, IRelationCollection relations, Boolean allowDuplicates, IGroupByCollection groupByClause, ITransaction transactionToUse, Int32 pageNumber, Int32 pageSize) in C:\Project\InvoiceSystem\LLBLGen\DaoClasses\TypedListDAO.cs:line 49
   at Pesco.LlblGen.TypedListClasses.InvoiceTypedList.Fill(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IPredicate selectFilter, ITransaction transactionToUse, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in C:\Project\InvoiceSystem\LLBLGen\TypedListClasses\InvoiceTypedList.cs:line 204
   at Pesco.LlblGen.TypedListClasses.InvoiceTypedList.Fill(Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, Boolean allowDuplicates, IPredicate selectFilter) in C:\Project\InvoiceSystem\LLBLGen\TypedListClasses\InvoiceTypedList.cs:line 152
   at Windows.Forms.MainForm..ctor() in C:\Project\InvoiceSystem\Windows\Forms\MainForm.cs:line 30

loren
User
Posts: 14
Joined: 29-Jul-2006
# Posted on: 19-Jul-2008 19:46:44   

OK, I've gotten a little sleep so I'm coming at this fresh again. I tried to refresh the catalogs within LLBLGen and received an E_FAIL(0x80004005) error message during GetSchemaRowset. From the following posts, I can see the this is something I need to sort out with the Access database:

loren
User
Posts: 14
Joined: 29-Jul-2006
# Posted on: 19-Jul-2008 23:23:56   

I didn't completely get to the bottom of this, but I figured out enough that I'm going to move on. Hopefully this will help someone else stuck on this issue...

Some of my tables are attached (linked) tables that pull data from another Access database. Any attached (linked) table containing a field with an Access data type of “Currency” caused the E_FAIL(0x80004005) error message when I tried to refresh the LLBLGen model. This is because the OleDb function GetSchemaRowset fails. If I delete all attached tables that use data type "Currency", I can refresh the model.

Instead of attaching the tables, I imported them into the database and I could also refresh the model. When I refreshed the model, the only changes I found were that the Currency fields had a Scale of 2 instead of 0. As far as I can tell, that is the only difference in the new LLBLGen model.

The odd thing is that this application is currently working in production at several offices using exactly the same OleDb driver version that I am using here. As far as I can tell, the only difference is that they are running against LLBLGen v2.0 libraries and I'm running against LLBLGen v2.6 libraries. Other than that, we have the same OleDb driver version (4.0.9502.0) and same versions of Microsoft Office (2003) installed. Based on the error messages, I thought this problem was related to the OleDb drivers, but that doesn't seem to make sense now.

Final Lesson: Based on this and other forums, there appear to be two main causes of the E_FAIL(0x80004005) message while reading a Microsoft Access schema through the OleDb provider:

  • MS Access queries are not expressed with brackets around the table and field names (e.g. "[table].[field]".)
  • Linked tables cause problems... While this turned up in a couple places, no one seemed to have a good explanation for why they cause problems. In my case, I believe it is because they contained "Currency" fields, but I'm not 100% sure.One last note: Microsoft Access is evil. Thank goodness I'm moving this to SQL Server. simple_smile