Wrong database after switchServer

In our application we use switchServer on the initApplication to set the correct database for the logged user.
Sometimes we are having a problem where records are created in the original DB, and not in the correct switched server DB.
This problem happens intermittently and until now we couldn’t find a way to reproduce (and hopefully fix) it in our development environment.

We don’t call switchServer again in the application. There’s anything else that could break it?

Thank you in advance

Check if you’re using some plugins in your code : Servoy doesn’t automatically switch the server so you have to give the correct database name in those cases.

studiomiazzo:
Check if you’re using some plugins in your code : Servoy doesn’t automatically switch the server so you have to give the correct database name in those cases.

The records are created in a foundset, I think the plugins shouldn’t have any interference in that.

The only one that is not switched is rawSQL, everything else points to the switched server. Are you sure that the switchServer call is not failing when invoked? When do you call it is there any foundset already in place before the call? Does it happen only for some foundsets or for any table faoundset on that server connection?

ngervasi:
Are you sure that the switchServer call is not failing when invoked?

yes, we close the application if it fails.

ngervasi:
When do you call it is there any foundset already in place before the call?

It could be. I need to carefully check the code to be sure, but could that make a difference?

ngervasi:
Does it happen only for some foundsets or for any table faoundset on that server connection?

It happens to any table foundsets.
One moment you have a table view with the records, you do some operation, and the next time you refresh the foundset (find, reload), all the records disappear.
If you open some form that was never open before for some different table, it’s empty too.
It’s really like if for some reason switchServer stops working, and you are back in the original server, that in this case is completely empty.

jbrancoIF:

ngervasi:
When do you call it is there any foundset already in place before the call?

It could be. I need to carefully check the code to be sure, but could that make a difference?

This should be avoided, the switch should be done before any foundset is created against that server.

jbrancoIF:
One moment you have a table view with the records, you do some operation, and the next time you refresh the foundset (find, reload), all the records disappear.
If you open some form that was never open before for some different table, it’s empty too.
It’s really like if for some reason switchServer stops working, and you are back in the original server, that in this case is completely empty.

Do you have any errors in the log when this happens?
Is it possibile that this happens when a db connection goes on time out and a new one is opened? (this is a question that should be asked to Servoy support) What database are you running and what connection validation method are you using?

Finally found the problem!

If you use switchServer, and let user cancel the solution close in the smart client, you’ll be back in the source server.

Case created: