Random Exception from DataAccessAdapterBase.ReadRowIntoFields

Posts   
 
    
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 02-Dec-2010 18:20:39   

I am having a random failure in a query. The table that is being queried is not changing during my usage. I can't categorically say this is the issue, but I ran 6700 processes (each calling this once) without this failing. In the next 600 runs, I've had this failure about 80 times. If I re-run the same test, it nearly always succeeds.

LLBLGen version: 2.6 Final (October 9th, 2009) Runtime version: 2.6.09.1202 Using Adaptor on .Net4 Database is Postgres 8.3, Npgsql v 2.0.6.0

System.InvalidCastException: Unable to cast object of type 'System.Int32' to type 'System.String'. at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ReadRowIntoFields(Object[] values, IEntityFields2 rowDestination, List1 fieldIndexToOrdinal, IFieldPersistenceInfo[] fieldsPersistenceInfo) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.CreateEntityInstanceFromReaderRow(IEntityFactory2 entityFactory, IFieldPersistenceInfo[] fieldsPersistenceInfo, Int32 numberOfFieldsInQuery, InheritanceHierarchyType typeOfHierarchy, Dictionary2 hierarchyFieldAliasesToOrdinals, List1 fieldIndexToOrdinal, Dictionary2 entityFieldStartIndexesPerEntity, Boolean hasExcludedFields, IFieldPersistenceInfo[] persistenceInfosForRowReader, Object[] valuesOfRow, IEntityFactory2& entityFactoryToUse) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.ExecuteMultiRowRetrievalQuery(IRetrievalQuery queryToExecute, IEntityFactory2 entityFactory, IEntityCollection2 collectionToFill, IFieldPersistenceInfo[] fieldsPersistenceInfo, Boolean allowDuplicates, IEntityFields2 fieldsUsedForQuery) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollectionInternal(IEntityCollection2 collectionToFill, IRelationPredicateBucket& filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityCollection(IEntityCollection2 collectionToFill, IRelationPredicateBucket filterBucket, Int32 maxNumberOfItemsToReturn, ISortExpression sortClauses, IPrefetchPath2 prefetchPath, ExcludeIncludeFieldsList excludedIncludedFields, Int32 pageNumber, Int32 pageSize) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProvider2.ExecuteEntityProjection(QueryExpression toExecute) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.ExecuteExpression(Expression handledExpression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProProviderBase.System.Linq.IQueryProvider.Execute(Expression expression) at SD.LLBLGen.Pro.LinqSupportClasses.LLBLGenProQuery`1.SD.LLBLGen.Pro.LinqSupportClasses.ILLBLGenProQuery.ExecuteTResult at Zetec.Analysis.QueryHelper.GetOutages(String exclude_me) <snip the rest of my callstack>

The call to GetOutages is being passed "ONS2_EOC24_Revo_Reso"

      //exclude_me is for the current outage, if you don't want it
      public static EntityCollection<OutageEntity> GetOutages(string exclude_me)
      {
         EntityCollection<OutageEntity> ret;
         using (DataAccessAdapter adapter = Create.Adapter())
         {
            LinqMetaData metaData = new LinqMetaData(adapter);
            if (string.IsNullOrEmpty(exclude_me))
            {
               ret =
                  ((ILLBLGenProQuery)from o in metaData.Outage
                                     orderby o.InspectionDate descending
                                     select o).Execute<EntityCollection<OutageEntity>>();
            }
            else
            {
               ret =
                  ((ILLBLGenProQuery)from o in metaData.Outage
                                     where o.Name != exclude_me
                                     orderby o.InspectionDate descending
                                     select o).Execute<EntityCollection<OutageEntity>>();
            }
         }
         return ret;
      }
CREATE TABLE outages (
   name text PRIMARY KEY, --if we update the name of the outage, those entries referencing it should get their entry updated - llbl instructions http://www.llblgen.com/tinyforum/Messages.aspx?ThreadID=630
   number int2 NOT NULL,-- the number of the outage because we can't count on the dates
   inspection_date date,
   comment text
);

Contents of outages table:

"EOC24 - 04/09";5;"2009-04-30";"Imported From HMS" "ONS2_EOC24_Revo_Reso";9999;"2010-08-09";"Created by analysis since it didn't already exist" "ONS3_EOC25_Revo";9999;"2010-10-27";"Created by analysis since it didn't already exist"

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 03-Dec-2010 04:23:46   

Hi there,

I created your DB, code the test and run it X times (X between 6000 and 8000) and I can't reproduce it. I also tested in with multiple threads.

Could you create a repro project for this?

David Elizondo | LLBLGen Support Team
Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 03-Dec-2010 10:10:18   

What does 'Create.Adapter()' do? Does it cache the adapter if created? If so, that's the cause. never cache the adapter instance or share it among threads. A website uses multiple threads, 1 for each request (more or less). A dataaccessadapter instance is lightweight and can be created without any overhead.

Frans Bouma | Lead developer LLBLGen Pro
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 03-Dec-2010 14:53:45   

It just accesses a global to get the connection string and checks database versions after creation. A new adapter each call.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 39908
Joined: 17-Aug-2003
# Posted on: 03-Dec-2010 17:38:24   

As we couldn't reproduce it, we tried to find other reasons. Please help us find out what the reason is, as you probably missed David's reply that he couldn't reproduce your problem.

IMHO it's clearly a threading issue, but where it originates (and thus where to look for solutions) is not clear. In any case, please check whether you have the proper npgsql build and if there aren't newer builds which might fix a threading issue (you might need to setup an assembly redirect in that case).

Frans Bouma | Lead developer LLBLGen Pro
tmatelich
User
Posts: 95
Joined: 14-Oct-2009
# Posted on: 03-Dec-2010 17:50:42   

Yeah, I plan to try to make a test app today and I will look into trying a newer version of npgsql. Some more detail on what's happening.

There are 16 apps selecting, deleting, and inserting from various tables, eight on one machine, 8 on another. Each application is essentially single threaded, all the work is performed on one BackgroundWorker thread.

The database server is on a third machine, and the database instance is only being used by this setup.

daelmo avatar
daelmo
Support Team
Posts: 8245
Joined: 28-Nov-2005
# Posted on: 04-Dec-2010 08:55:15   

I see. We are looking forward for your repro app so we can't help you to find a solution.

David Elizondo | LLBLGen Support Team