22
Views
10
Comments
Outsystems automatically renaming tables from 2 different databases

Hi 

I am trying to switch between external databases at runtime using DatabaseConnection_SetConnectionStringForSession action where the UI will be same and the user will switch between the databases once he logs in based on the particular session.

When I try this, I have 2 tables with same structure and same names in 2 different external databases. When I import one table, Outsystems automatically renames it as <TableName2> and when I use it in the Advanced SQL Query as just <TableName> for retrieving the data, it always retrieves the data from the DB 1 as the table from DB 2 is renamed as <TableName2>. 

Can someone let me know if there is any other way to overcome this so that when I use the tablename in any aggregate or SQL Query, the table used changes to particular table belonging to that database based on the session set using the connection string?


Thanks is Advance!

You are defining the database connection extension twice. You have to change the data base connection in the connection extension and use only one connection dependence. 

I do not have an example to show you. 

But we can think together:

- You need both databases info at the same time? 

To take advantage from the DatabaseConnection_SetConnectionStringForSession you must be using only one database at each moment, this action changes the database that is used by  "connection" your extension uses. 

If so you don't need to access the " table2", "table1" will have the data from the database you are using at the moment.   

Tell me something. 


Can you check your integration studio , Just to make sure you have not hard coded the Entity and Table.


More in below Q&A.

https://www.outsystems.com/forums/discussion/63074/change-in-runtime-the-external-database-connection/


Regards,

Rama

And read also 

https://success.outsystems.com/Documentation/10/Reference/OutSystems_APIs/PlatformRuntime_API#DatabaseConnection_SetConnectionStringForSession


Then test it, forget the connection  you have done for "DB2" and test the change-in-runtime-the-external-database-connection, see what are the results from your SQL when using one or the other data bases. 

Rank: #516

I totally agree with Maria da Graça Peixoto.

You don't need to create two extensions. You only need to create one extension and let DatabaseConnection_SetConnectionStringForSession  do the trick.

Also please refer to DatabaseConnection_SetConnectionStringForSession  document bellow.

The document has some points you should be careful when using DatabaseConnection_SetConnectionStringForSession  

https://success.outsystems.com/Documentation/11/Reference/OutSystems_APIs/PlatformRuntime_API


Rank: #516

Hi Ravali Perni 

I tried to remove the database and schema name. It's worked for me.

Can you also provide an example of the connection string?

Regards