- Home
- LLBLGen Pro
- LLBLGen Pro Runtime Framework
Constraints oddity
Joined: 15-Jan-2005
Been grappling with an odd one this afternoon, still not 100% sure what is causing it but thought I'd share:
It involves a simple fetch using a constraint in SQL2000.
My code is like so: DataAccessAdapter adapter = new DataAccessAdapter(); SerActsCompositeEntity entActComp = new SerActsCompositeEntity(); entActComp.KeyFact = KeyAct; adapter.FetchEntityUsingUniqueConstraint(entActComp, entActComp.ConstructFilterForUCKeyFact());
This worked fine until I changed a field in the table SerActsComposite (forgive the stupid names!). All I did was add a new field. After doing this and regenerating the LLBLGen project I started getting the following error: System.IndexOutOfRangeException: Index was outside the bounds of the array. (full error below)
This made no sense as it worked before and also: The constraint definately exists KeyAct definately exists A related record definately exists
After completely dismantleing the database numerous time I have found that after adding a field to a table one has to: 1) Remove the constraint 2) Add it back using a new name 3) Regenerate the project
Thanks
Joined: 15-Jan-2005
Server Error in '/' Application.
Index was outside the bounds of the array. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.IndexOutOfRangeException: Index was outside the bounds of the array.
Source Error:
Line 92: // Get data Line 93: DataAccessAdapter adapter = new DataAccessAdapter(); Line 94: adapter.FetchEntityUsingUniqueConstraint(entService, entService.ConstructFilterForUCServiceUrl(), prefetchPath); Line 95: Line 96: // ## GET ACT ENTITY
Source File: c:\inetpub\wwwroot_controls\adviceinfo\services\entertainment\detail.ascx.cs Line: 94
Stack Trace:
[IndexOutOfRangeException: Index was outside the bounds of the array.] SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32& uniqueMarker) +2360 SD.LLBLGen.Pro.DQE.SqlServer.DynamicQueryEngine.CreateSelectDQ(IEntityFieldCore[] selectList, IFieldPersistenceInfo[] fieldsPersistenceInfo, IDbConnection connectionToUse, IPredicate selectFilter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) +101 HousingCare.LLBLGen.DatabaseSpecific.DataAccessAdapter.CreateSelectDQ(IEntityFields2 fieldsToFetch, IFieldPersistenceInfo[] persistenceInfoObjects, IPredicateExpression filter, Int64 maxNumberOfItemsToReturn, ISortExpression sortClauses, IRelationCollection relationsToWalk, Boolean allowDuplicates, IGroupByCollection groupByClause, Int32 pageNumber, Int32 pageSize) in C:\Documents and Settings\John.CHEWBACCA\My Documents\LLBLGen Pro Projects\Housingcare\DatabaseSpecific\DataAccessAdapter.cs:590 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingFilter(IEntityFields2 fieldsToFetch, String entityName, IPredicateExpression filter) +158 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter) +82 SD.LLBLGen.Pro.ORMSupportClasses.DataAccessAdapterBase.FetchEntityUsingUniqueConstraint(IEntity2 entityToFetch, IPredicateExpression uniqueConstraintFilter, IPrefetchPath2 prefetchPath) +26 HousingCare.Controls.AdviceInfo.Services.EntertainerDetails.Page_Load(Object sender, EventArgs e) in c:\inetpub\wwwroot\_controls\adviceinfo\services\entertainment\detail.ascx.cs:94 System.Web.UI.Control.OnLoad(EventArgs e) +67 System.Web.UI.Control.LoadRecursive() +35 System.Web.UI.Control.LoadRecursive() +98 System.Web.UI.Control.LoadRecursive() +98 System.Web.UI.Control.LoadRecursive() +98 System.Web.UI.Control.LoadRecursive() +98 System.Web.UI.Control.LoadRecursive() +98 System.Web.UI.Page.ProcessRequestMain() +725
Version Information: Microsoft .NET Framework Version:1.1.4322.573; ASP.NET Version:1.1.4322.573
Request Details
Session Id: ky52rcqyhqxy3kfxk3pfysmv Request Type: GET
Time of Request: 03/03/2005 16:31:29 Status Code: 500
Request Encoding: Unicode (UTF- Response
The error you got doesn't have a relation with the unique constraint.
I think what happened is that you regenerated the code but only one of the 2 projects was actually updated on the webserver. This means that when the query had to be created, the fields collection contains 11 fields (for example) and the persistence info array contains 10 positions. Could you check if this is the case, i.e.: that the database specific project was also updated on teh webserver?
Joined: 06-Jun-2005
I think I am having the same problem with one of my entities.
DAL.HelperClasses.EntityCollection oUserTypes = new EntityCollection(new DAL.FactoryClasses.UserTypeEntityFactory());
if(oUser.DomainUserName == string.Empty)
{
this.oErrorLog.ErrorLog("CreateUser - DomainUserName Empty");
oDataAdaptor.Dispose();
return false;
}
if(GetUserByLoginID(oUser.DomainUserName) != null)
{
this.oErrorLog.ErrorLog("CreateUser - Username exists");
oDataAdaptor.Dispose();
return false;
}
// get default user type
IRelationPredicateBucket filter = new RelationPredicateBucket();
filter.PredicateExpression.Add(PredicateFactory.CompareValue(DAL.UserTypeFieldIndex.Name, ComparisonOperator.Equal,"Reporting User" ));
this.oDataAdaptor.FetchEntityCollection(oUserTypes,filter,1);
if(oUserTypes.Count < 1)
{
this.oErrorLog.ErrorLog("CreateUser - No UserTypeReturned");
oDataAdaptor.Dispose();
return false;
}
else
{
oUser.UserTypeId = ((UserTypeEntity)oUserTypes[0]).Id;
}
// save user and refetch saved user
try
{
oDataAdaptor.StartTransaction(IsolationLevel.ReadCommitted, "Inserts");
string saveName = oUser.DomainUserName;
this.oDataAdaptor.SaveEntity(oUser,true,null,true);
oUser = GetUserByLoginID(saveName);
if(oUser != null)
{
oProfile.UserId = oUser.Id;
}
oProfile.IsNew = true;
oUser.UserProfile.Add(oProfile);
Exceptions is thrown here ---> this.oDataAdaptor.SaveEntity(oUser);
oDataAdaptor.Commit();
}
catch(Exception ex)
{
oDataAdaptor.Rollback();
throw ex;
}
finally
{
oDataAdaptor.Dispose();
}
Every time I get this error message not sure how to fix this.
[SoapException: Server was unable to process request. --> Index was outside the bounds of the array.]
I added a field to the UserProfile table and afterward began having troubles.
Also, setting the refetch to true here: this.oDataAdaptor.SaveEntity(oUser,true,null,true); did not refetch the entity. must I do something different inside of a transaction to refetch?
Thanks.......
Joined: 06-Jun-2005
Otis wrote:
You've to make sure the database SPECIFIC project is updated as well on the server and that you 've updated the database GENERIC project on both client AND server.
Well I did read your previous answer and I deleted all of the DLL,s client and server and deleted all of the generated code. Then I regenerated the code and re-built the dlls. Still I am having the same problem. After the latest post I deleted all of the dll's again rebuilt and still have the same problem.
Perhaps, you can share some insight on what causes the exception. It would seem that perhaps the code is not being properly regenerated after a change to the database tables. Although, since the exception isn't very verbose this is just a guess.
I am using SQL Server.
Finboy wrote:
Otis wrote:
You've to make sure the database SPECIFIC project is updated as well on the server and that you 've updated the database GENERIC project on both client AND server.
Well I did read your previous answer and I deleted all of the DLL,s client and server and deleted all of the generated code. Then I regenerated the code and re-built the dlls. Still I am having the same problem. After the latest post I deleted all of the dll's again rebuilt and still have the same problem.
Perhaps, you can share some insight on what causes the exception. It would seem that perhaps the code is not being properly regenerated after a change to the database tables. Although, since the exception isn't very verbose this is just a guess.
I am using SQL Server.
I can also only guess, and re-reading your code and your remark about 'I added a field and then it went wrong' I conclude that some entity's fields are not in sync with the persistence info information, i.e. the DB specific project. This means that the entity has 10 fields for example and the array with persistence info has 9 fields. This happens when the DB generic project (which contains the entity definitions) is updated after a field has been added, and the db specific project (which contains the persistence info for each entity) isn't.
As the exception happens inside the SaveEntity method, that's what I think happens.
Joined: 06-Jun-2005
Otis wrote:
I can also only guess, and re-reading your code and your remark about 'I added a field and then it went wrong' I conclude that some entity's fields are not in sync with the persistence info information, i.e. the DB specific project. This means that the entity has 10 fields for example and the array with persistence info has 9 fields. This happens when the DB generic project (which contains the entity definitions) is updated after a field has been added, and the db specific project (which contains the persistence info for each entity) isn't.
As the exception happens inside the SaveEntity method, that's what I think happens.
Well I deleted every file from the project directory. including the bin and obj folder for both the Generic and Specific projects. Then I re-ran the Generator. This seems to have updated the project properly. It would seem that the Generator should update the source files. I would think deleting the source files should have fixed the issue as they get replaced. Perhaps there is an intermediate file that was not being replaced.
Finboy wrote:
Otis wrote:
I can also only guess, and re-reading your code and your remark about 'I added a field and then it went wrong' I conclude that some entity's fields are not in sync with the persistence info information, i.e. the DB specific project. This means that the entity has 10 fields for example and the array with persistence info has 9 fields. This happens when the DB generic project (which contains the entity definitions) is updated after a field has been added, and the db specific project (which contains the persistence info for each entity) isn't.
As the exception happens inside the SaveEntity method, that's what I think happens.
Well I deleted every file from the project directory. including the bin and obj folder for both the Generic and Specific projects. Then I re-ran the Generator. This seems to have updated the project properly. It would seem that the Generator should update the source files. I would think deleting the source files should have fixed the issue as they get replaced. Perhaps there is an intermediate file that was not being replaced.
Could be, if your files are in sourcesafe for example. Always check the generator log for errors, they're displayed in red. Files which should have been written but couldn't because of a read-only flag on the file are marked as errors.