LLBLGen Pro v2.6 on Windows Server 2012 R2 on AWS

Posts   
 
    
Posts: 5
Joined: 10-Oct-2019
# Posted on: 10-Oct-2019 12:25:36   

We are in process of migrated one of our websites from on premise Windows Server 2008 to AWS Windows 2012 R2. However it's throwing an exception when we are invoking method FetchEntity(). Not sure if it is a compatibility issue or access problem on the new environment. Can you please advise?

Otis avatar
Otis
LLBLGen Pro Team
Posts: 38110
Joined: 17-Aug-2003
# Posted on: 10-Oct-2019 14:44:00   

" However it's throwing an exception " Without knowing what kind of expression and a stacktrace it's hard to tell what it is...

Posts: 5
Joined: 10-Oct-2019
# Posted on: 11-Oct-2019 10:15:15   

Below expression is not evaluating and giving no output

GetAdapter().FetchEntity(user)

Where

"user" is login user name and

protected DataAccessAdapter GetAdapter() { DataAccessAdapter adapter = new DataAccessAdapter(this._connectionString); adapter.CatalogNameUsageSetting = SD.LLBLGen.Pro.ORMSupportClasses.CatalogNameUsage.ForceName; adapter.CatalogNameToUse = this._catalogName; return adapter; }

Hope above information helps, please let me know if I can provide more details.

Walaa avatar
Walaa
Support Team
Posts: 14643
Joined: 21-Aug-2005
# Posted on: 11-Oct-2019 10:49:50   

Sorry, we need the exception text, and the stack trace.

Posts: 5
Joined: 10-Oct-2019
# Posted on: 15-Oct-2019 09:48:55   

Error is: "The entity is out of sync with its data in the database. Refetch this entity before using this in-memory instance."

Stack Trace:

at SD.LLBLGen.Pro.ORMSupportClasses.EntityBase2.GetValue(Int32 fieldIndex, Boolean returnDefaultIfNull) at CAG.REG.Security.LLBLGen.EntityClasses.SecurityUserEntity.get_IsActive()

Walaa avatar
Walaa
Support Team
Posts: 14643
Joined: 21-Aug-2005
# Posted on: 15-Oct-2019 22:01:43   

The stack trace is not complete, but anyway, I guess you are trying to access a property of the user entity (IsActive), while the entity seems out of Sync with the database.

So I think upon login, you fetch the entity, modify some fields, for example "last login date", then you save the entity, and immediately afterwards you are accessing the IsActive property.

When you save an entity to the database, please make sure you re-fetch it, to make sure all field values are in sync with the database.

To re-fetch upon save, you should find an overload of the SaveEntity() method which accepts a Boolean refetch parameter.

Posts: 5
Joined: 10-Oct-2019
# Posted on: 23-Oct-2019 17:35:17   

Thanks Walaa for your response. I would like to confirm that we are not saving the entity at the time of login. How can I re-fetch without saving an entity?

Walaa avatar
Walaa
Support Team
Posts: 14643
Joined: 21-Aug-2005
# Posted on: 24-Oct-2019 02:29:04   

Same way you fetched the entity in the first place.

Otis avatar
Otis
LLBLGen Pro Team
Posts: 38110
Joined: 17-Aug-2003
# Posted on: 24-Oct-2019 11:16:39   

That or mark the entity as 'fetched': myCustomer.Fields.State = EntityState.Fetched;

however this exception stems from the fact you have either a new entity instance (which fields have no meaning, so check the IsNew property!) or you have saved an entity and read the fields afterwards.

Posts: 5
Joined: 10-Oct-2019
# Posted on: 24-Oct-2019 11:27:04   

Hi Otis,

Please have a look into my code below which is throwing outofsync exception. As you can see I am already marking State as Fetched, but still having issues.

public bool IsEnabled(string networkLogin) { SecurityUserEntity user = new SecurityUserEntity(base._applicationName, base._environmentName, networkLogin); user.Fields.State = EntityState.Fetched;

        if (GetAdapter().FetchEntity(user))

            return user.UserIsEnabled;

        else
            throw new Exception("User <" + networkLogin + "> does not have access to this application <" + _applicationName + "> <" + _environmentName + ">");
    }
Walaa avatar
Walaa
Support Team
Posts: 14643
Joined: 21-Aug-2005
# Posted on: 24-Oct-2019 17:33:20   

Can you please post the complete stack trace and line of code where the exception is raised?