FMX Phone App using Aurelius giving "Database Name exists" error

I have a phone application. The front end is FMX, the backend is an Aurelius Server. It is accessing an ElevateDB database on an Amazon AWS EC2 Instance.

I am using a TMS Aurelius / XData server on the back-end, with Aurelius components on the App to access data.

It has worked well in testing.

Now we are moving to production-testing and we are getting an error

"Database name 'XXXXXXXXX' already exists"

Note that I have followed advise to set up the ElevateDB database components BUT leave the Name blank. Aurelius then uses this database component to create it's own databases as it needs them.

I have done this exactly as shown in the TMS help, and it works fine while there is only 1 or 2 users connected.

Now I have a slightly higher load on the App I am getting the error above.

I think it occurs when 2 users call| "insert" at roughly the same time.

I am not using Transactions. I would not usually use Transactions with a VCL ElevateDB app, as it manages these processes well itself. I don't know whether I should try to start using them now.

Please refer to:

The EDBDatabase component name is blank. The Database and Session are not connected at design time. I have added the "BeforeConnect" Event as per your description in prior questions on this group.

The server works well with a single user, but once there are multiple users the "Database Name 43251446534" message occurs occasionally.

I am using code from a previous question on this group:

procedure TServerContainer.EDBDBBeforeConnect(Sender: TObject);
DB: TEDBDatabase;
DB := TEDBDatabase(Sender);
if DB.DatabaseName = '' then
DB.DatabaseName := IntToStr(NativeInt(DB));

As mentioned in the other e-mail, it should be simple. Are you debugging your application and investigating if a different database name is being set for each different TEDBDatabase component? I assume your VCL client application works? If yes, how is it different from the mobile one?

The thing is there is only 1 database component in my application. If more than 1 are being created this is being done by Aurelius somewhere under the hood where I cannot see it.

In terms of debugging, I can put a break point in the "BeforeConnect" of the database, but that does not tell me why the database is being re-created.

The error message I am seeing indicates 2 database objects with the same name. These multiple instances must be being created by Aurelius. If a second instance is created I would assume it would also have a blank name, if it is being created using the component on my data module. I am not clear how the second creation process would randomly land on the same database name as the first instance.

Perhaps I should use a time-stamp to set the database name to ensure they will be different??

I have not used the suggested code:

DB.DatabaseName := IntToStr(NativeInt(DB));

in the past, so I am not clear whether it would always produce a unique integer, but I am assuming it is written in that way to guarantee t will always give a different result.

You can see if during debugging if you analyze the call stack, you will see where it's coming from.

I don't know, you never told me how your application is organized. I understand this error happens client side (phone) and no server is involved?

You can try.

Why not?

I have not used the suggested code:
Why not?

Sorry Wagner, you mis-read my statement: I meant to say "I have not used this type of code before"

I have copied the TMS code blindly without being sure exactly how it would perform. I think that you wrote the original code, but I included it in the post with the intention that you could see what I have done in case there is an error.

. I understand this error happens client side (phone) and no server is involved

The error occurs when the App calls the server for data and the server fails to respond. The error is returned from the server.

I will try to look at the call stack as you suggest, but can I confirm that the code I quoted at the start is correct for what you would expect to be needed in the EDB BeforeConnect event?

Then it shouldn't matter if it's a phone app or VCL app. The problem is the same as I mentioned in the other topic: for each request a copy of TEDBDatabase is made and - unfortunately by a limitation that only happens with ElevateDB database - it doesn't allow same database names for two different components.

Thank you for your support Wagner.

Would it work for me to write a descendent of the ElevateDB database component and use that to act as the database component for my application?

If I had my own descendent component I could include code in it's Constructor to provide a unique name, so every instance was different.

Would Aurelius create instances of my descendent database (TmyDatabase), or would it expect to just create an ElevateDB (TEDBDatabase) database?

Yes, it should work.

If a copy is made, it certainly replicates DB.DatabaseName value, so shouldn't we delete this [ if DB.DatabaseName = '' then ] and let it assign the "new" name everytime it goes through OnBeforeConnect ?

Maybe, yes, but if the original DatabaseName is empty, why is this a problem?

At least this guarantees that the same instance won't change its DatabaseName all the time it reconnects, I don't know ElevateDB enough to tell if this can cause a problem.

But it won't change. It's using the object's address as a DatabaseName. Ok, maybe it'll fire some Setter, but if it's the same object, the value will remain the same. If it's a copy, as you mentioned, it'll be a new value, avoiding that error.