Change Database connection

Change Database connection

I have the following problem:

During a part of the day a readonly database is not available therefor i would like to perform the following steps automaticly (in SQL job):

- change database connection string to copy database, so all application are useing this copy database
- perform update
- change database connection to original database

Is it possible to change the database connection on the fly? I tried to do it from service center but after changing the connection string he applications are still using the previous settings.

I would like to do this with a Timer or sql-job, is this possible?

Kind regards,

Matthias Preuter

Hi Matthias,

That sounds like you're trying to do some complex things in runtime. What exactly are you trying to do? Is it the whole OutSystems database that you want to redirect the connection string, or is it just a specific database with which you integrate?

Let us know so someone can better try to help you.


Paulo Tavares

We are using a Extension_A that uses a database A (this is configured in the Database connection DC_DBA). At runtime i want to change the connection string of Database connection A to database B.

Above sample is done manually at Service center  Administration / Database Connections / DC_DBA, and then change the Server, but when i change this connection string (Server / Catalog / Username / Password) then the Extension_A it looks like it's still using the previous  DC_DBA connection string.

We have the following questions:
- Do i have to redeploy eSpaces or do a IIS_reset? or is there another way to force that Extension_A uses the new database connection?
- And how can i perform this automatically in a timer or job?

Hope this helps explaining our problem.

Kind regards,


Hi Matthias,

Even though I think the way you are trying to do is the best one for your situation, I would like to present two alternative options for doing this:
  • You can create both Database Connections in Service Center and then switch Logical Database configuration for the extension each time you want to change (on the Operation tab of the extension in Service Center). Note that this option would be the most usual, but since it requires the compilation of the consumer eSpaces I don't think it is suitable for this particular situation.
  • You can create both Database Connections in Service Center and use two different extensions (or just one with both table mappings) and make the logic in you eSpace to call the correct one depending on some availability configuration.

For your situation chaging the configuration in Service Center (like you explained in your post) actually seems the best option.
Unfortunately there is no easy way of doing that automatically, since the connection string is not in clear text for security reasons.

As for the problem about "it looks like it's still using the previous  DC_DBA connection string", what feedback does it show when you click the Save button?
A green success mesage or a Warning saying the affected eSpaces need to be compiled?

The only thing necessary to update the connection string of a modified Database Connection usage in an eSpace is a TenantInvalidateCache, unless you change the name of the Database Connection or the Database type (those changes would require the compilation of the eSpace).

I just tryed it and worked perfectly on my server (Platform Server 5.1), what version of the Platform are you using?

Also, just to remember you that to make that type of switching, in the entity definition inside in extension the Physical Table Name should not be prefixed by the "database.schema.", unless the servers are really independent and the database name and chema are the same in both.

João Rosado

We are using OS 4.2, after changing the database settings a green succes message appears "Database Connection successfully updated.", but the extension using this db-setting is stil using the old db-settings.