Changing the database using and action from the RuntimePublic_API does not work


for various reasons we have to implemnt a Multi Tennant capability into ourr Application by using multiple identical Databases. There we at least at application start to pick one database the application shall work with. Maybe we want allow tha some users might chnage the database ( and by doing so they change the tennant) during a session.

We found this nice action   ( DatabaseConnection_SetConnectionStringForSession  ) from the Runtime Public_API ( )  that is supposed to do exactly what we want - but we can't make it work properly.

We use
Our licenses allows the usage of the RuntimePublic_API.
We created for both databases connections in Service Center ( and they work)
Both Database  connections are referenced within the application.
For test reasons we just perform simple select statements - so there should not be any open request that could keep the database connection from changing.
We dont get any runtime errors or error messages in Service Center.

Is there aynbody out there who managed to use this action to change a database connection at runtime and could share his experience with us?

Any help appreciated.

Hi Joerg,

Common problems when using that API:
  • Most usual: Entities that you defined in the Integration Studio should not have the names with catalog prefixes. For example if you have the entities there defined with "MyCatalog1"."dbo"."MyTable", you should just leave it as "MyTable" (assuming it will also exist in the other catalog).
  • Connection name is the final name of the Database Connection, as it is shown in Service Center (this means, not the "logical name" defined in Integration Studio).
  • In SQL Server: in the connection string parameter you need to pass the Initial Catalog (just like the connection string shows in Service Center when you configure the database connection)
  • In Oracle: you need to fill the oracleInitialSchema parameter with the correct schema

Let me know if this helps.

João Rosado
Hi João,

thanks for the reply. your tips have not helped. The Entities that we defined in the Integration Studio have not the names with catalog prefixes, Connection name and connection string are the same as in the service center and we use a SQL Server. have you another idea? 

another question on this topic:
it is necessary that both Database connections are referenced within the application to use the action?


You only need to reference one extension.

Is the use of the action the first thing you do or are there any queries that use the connection before calling the action?

João Rosado
no,  the use of the action is the first thing. the screenshot shows the screen-action.
what is with the logical database propertie of an Entitie. when I delete the propertie an error is thrown in the browser. do you have an example app, that works?

Hi arne,

Attached you can fing a quick espace/extension I made to do a sample. My server setup is OutSystems Platform with SQL Server.

I created 2 extra catalogs in my server called "One" and "Two". In each catalog added a table called "MyTable" and gave permisions to the same user (just to simplify the sample)
Here is a screenshot of my database setup:

Screenshot of the Connection in Service Center and in the API call:

A video of using it:
Did multiple types of inteactions to show that after changing the connection string the configuration stays active during that user session. Not requiring to call the configuration on all requests.

Note: for sample purposes the connection string is hardcoded in the SwitchTo action of the eSpace and I edited with dummy username/password before downloading the solution.

João Rosado
Hi João,

thanks for the help. now it works. Our fault was that we use two Database Connection. So i change only the catalog name in the action (like in your app) and it works.

How does it works for Oracle, Oracle connection string is jdbc:oracle:thin:user/pwd@host:1521:sid , i have tried chaning the user with newuser  and pwd with newpwd and it failed with below error, i have newuser created in the oracle. 

ORA-01435: user does not exist
java.sql.SQLException: ORA-01435: user does not exist
   at oracle.jdbc.driver.T4CTTIoer.processError(
   at oracle.jdbc.driver.T4CTTIoer.processError(
Hi Vasanth,

I've used it with a Oracle Database a time ago.
the connectionString is something like
De database moest be in the tnsnames of outsystems (
/etc/outsystems/tnsnames.ora). (supported since

Regards Hans
Hi Hans, connection string is fine to me jdbc:oracle:thin:giny/pwd@localhost:1521:sid1 , i created the DB connection in the service center and it works fine, i could query. i have another schema named john when i use the DatabaseConnection_SetConnectionStringForSession to use this connection string  jdbc:oracle:thin:john/pwd@localhost:1521:sid1, it fails with the 'ORA-01435: user does not exist' error. 
Hi Vasanth,

I googled for the error and got this hit:
In that topic the error is the same that you are getting 'ORA-01435: user does not exist, but the problem was related to the schema and not the user.

What argument are you passing on that method as the schema parameter?

João Rosado
I pass giny or john based on the user who log in, i understood from above example that connection swtiching is based on the CATALOG in the SQL SERVER and I assume on Oracle it is based on the SCHEMA change,  required an oracle working example. 
Hi Vasanth,

very strange.. in my opinion it should work. Have you tried it by connecting as the user defined in the service Center?

yes, i created one DB connection in the Service Center. 
Vasanth wrote:
yes, i created one DB connection in the Service Center. 
 I mean: have you tried to use the DatabaseConnection_SetConnectionStringForSession with the same user and password as you have defined in Service Center? Just to be sure that works fine.
DatabaseConnection_SetConnectionStringForSession is not switching to john, whenever i login as john i get ORA-01435 error, however the giny is defined in the service center and whenever i login as giny i could get the response.
oke, perhaps john doesn't have the right to connect to the database. I suggest to set john as user in Service Center. 
Further, you can check if the parameter ConnectionName in your DatabaseConnection_SetConnectionStringForSession  action contains the right databaseconnectionname (the name you defined in Service Center). 
Another thing is to check if the databaseschema's are the same. 
And you can try to set the parameter oracleInitialSchema in the DatabaseConnection_SetConnectionStringForSession action as well to john or giny. 
I hope it's one of these.. 
Good luck,

1. As per above instructions, we should not have 2 db connections, incase i keep two connections, i always get GINY data back though i login as John or Giny,

2. yes, DB connection name is correct, 
3. In Oracle, each schema is one user, both Giny and John are different schema and different user. 
4. I have set the OracleInitialSchema to john or giny as per the login parameter.

No luck yet. 
Required a sample for Oracle, Chaning the parameter values has no impact, 

connectionName:   Having two connection in service center and changing this value is always returning 1st schema data. (Not retrieving the data from 2nd schema)
connectionString:  Changing the schema user and pwd in the connection string is throwing error “ORA-01435: user does not exist”
oracleInitialSchema: Changing this value has no impact, it always returns the 1st schema data. 
Issue has been sorted out, oracleInitialSchema value should be in CAPITAL. Thanks Hans for helping out..