# Connection with database server  on fly

**URL:** <https://forum.servoy.com/t/connection-with-database-server-on-fly/16613>\
**Category:** Classic Servoy\
**Created:** [October 8, 2012, 9:54pm UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613 "2012-10-08T21:54:21Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://forum.servoy.com/u/leonid)\
**Post date:** [October 8, 2012, 9:54pm UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/1 "2012-10-08T21:54:21Z")

</div>

Hi.  
Our solution suppose to allow users switch between data companies(multiple databases with same structure by company). I use databaseManager.switchServer command. It seems every thing works when I try to update,delete,insert data , but when I try to get server name on the form level ,using \_server\_name = databaseManager.getDataSourceServerName(controller.getDataSource()) it always return me the server name what I used during design.  
If somebody can explain how the switchServer works. It seems it done internally on the savedata, but in this case a lot off commands in DatabaseManager as for example, databaseManager.getDataSourceServerName is usefulness.

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [October 9, 2012, 7:11am UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/2 "2012-10-09T07:11:58Z")

</div>

Leonid,

When you switch from database server using databaseManager.switchServer(orig, new), the switch is transparent to all your code (with one exceptions).  
So all your forms and your code still works with the orig server and Servoy maps this to actual queries to the new server.  
controller.getDataSource() will also return the original server name.

One exception is the rawsql plugin, this plugin does not understand the mapping from databaseManager.switchServer() so there you have to use the new server name.

If you do not use the rawsql plugin you should not need to know in your code what the actual server is, otherwise you need to remember this in the code where you do the switchServer() call.

Rob

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [October 9, 2012, 8:11am UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/3 "2012-10-09T08:11:57Z")

</div>

Another question:  
I want to switch from _server1_ to _server2_, so I have to use:

```auto
DatabaseManager.switchServer(server1, server2)

```

Ok, but now I want to switch to _server1_ again. What’s the right code?

```auto
DatabaseManager.switchServer(server1, server1)

```

or

```auto
DatabaseManager.switchServer(server2, server1)

```

?

---

<div class="post-metadata">

**Author:** ![leonid](https://avatars.discourse-cdn.com/v4/letter/l/d9b06d/32.png) [@leonid](https://forum.servoy.com/u/leonid)\
**Post date:** [October 9, 2012, 11:14am UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/4 "2012-10-09T11:14:31Z")

</div>

Hi,  
Juan the server name suppose to switch before the forms loaded to solution. I just curious what happens if solution originally used 2-3 different databases.  
Thanks Rob, for your explanation.

---

<div class="post-metadata">

**Author:** ![rgansevles](https://avatars.discourse-cdn.com/v4/letter/r/3d9bf3/32.png) [@rgansevles](https://forum.servoy.com/u/rgansevles)\
**Post date:** [October 15, 2012, 7:31am UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/5 "2012-10-15T07:31:41Z")

</div>

This is the right code:

> juan.cristobo:
> 
> ```auto
> DatabaseManager.switchServer(server2, server1)
> 
> ```

---

<div class="post-metadata">

**Author:** ![juan.cristobo](https://avatars.discourse-cdn.com/v4/letter/j/df788c/32.png) [@juan.cristobo](https://forum.servoy.com/u/juan.cristobo)\
**Post date:** [October 15, 2012, 3:04pm UTC](https://forum.servoy.com/t/connection-with-database-server-on-fly/16613/6 "2012-10-15T15:04:41Z")

</div>

Ok, thanks, Rob.
