# Transaccions with Database.

**URL:** <https://forum.servoy.com/t/transaccions-with-database/3560>\
**Category:** Classic Servoy\
**Created:** [January 28, 2005, 8:32am UTC](https://forum.servoy.com/t/transaccions-with-database/3560 "2005-01-28T08:32:48Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![elmono\_acosta](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@elmono\_acosta](https://forum.servoy.com/u/elmono_acosta)\
**Post date:** [January 28, 2005, 8:32am UTC](https://forum.servoy.com/t/transaccions-with-database/3560/1 "2005-01-28T08:32:48Z")

</div>

The following example explains my problem, Iknow its not normal to do what you see on this method, this is only for the exmple.

```auto
databaseManager.startTransaction();

controller.newRecord();
dataprovider = 'test';

var query = "select dataprovider from tableA where dataprovider = 'test'"
var dataset = databaseManager.getDataSetByQuery('server', query, null, 100);

databaseManager.commitTransaction();

```

The problem is that when the query is launched, Servoy makes a NEW transaccion to the database, so the result is null because the data is not jet in the databae.

Servoy should use the same transaccion for everything that you do inside a startTransaction and commitTransaction

What can I do ???..I need to do everything inside, some times its no easy to search with servoy directly, it better with pure selects; mostly if you are serching with a lot of relationships with lots of tables.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [January 28, 2005, 10:10am UTC](https://forum.servoy.com/t/transaccions-with-database/3560/2 "2005-01-28T10:10:51Z")

</div>

I had sort of the same issue with invoking some relations after records were created.  
I solved this by calling:

```auto
controller.saveData();

```

Do this before you do your query.

Hope this helps

---

<div class="post-metadata">

**Author:** ![elmono\_acosta](https://avatars.discourse-cdn.com/v4/letter/e/b9e5f3/32.png) [@elmono\_acosta](https://forum.servoy.com/u/elmono_acosta)\
**Post date:** [January 28, 2005, 10:19am UTC](https://forum.servoy.com/t/transaccions-with-database/3560/3 "2005-01-28T10:19:48Z")

</div>

If I do that, I wont be able to rollback if I need to.

---

<div class="post-metadata">

**Author:** ![ROCLASI](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/roclasi/32/4371_2.png) [@ROCLASI](https://forum.servoy.com/u/ROCLASI)\
**Post date:** [January 28, 2005, 11:34am UTC](https://forum.servoy.com/t/transaccions-with-database/3560/4 "2005-01-28T11:34:13Z")

</div>

If you do the following you are still inside the transaction.

```auto
databaseManager.startTransaction(); 

controller.newRecord(); 
dataprovider = 'test'; 
controller.saveData();

var query = "select dataprovider from tableA where dataprovider = 'test'" 
var dataset = databaseManager.getDataSetByQuery('server', query, null, 100); 

databaseManager.commitTransaction();

```

All you are doing is telling Servoy to write it’s cache back to the database. The database is keeping track of the transaction anyway … not Servoy. So you can always rollback.  
(ofcourse not after you already have committed it, but that speaks for itself.)
