DBGrid data not updated until restarting app or DB connection

天大地大妈咪最大 提交于 2019-12-24 08:48:48

问题


I am using Delphi 10.2.3 and Firebird 2.5.8. I have small table with 2 fields (id & text) which I edit within of a subform and use the data on my mainform. On the subform I use DBGrid & DBNavigator. On each use, I create the form and destroy it afterwards.

On my subform I can see each time the updated data. After closing the subform I refresh my list within of my mainform but

SELECT Id,Text FROM Tbl_Test 

shows me only the old data.

I get the updated data only after restarting my program. Any idea what I could have done wrong? Btw. isql.exe also doesn't update the data. I have to restart isql. I tested Firebird 2.5.6 too - no difference in the behaviour.

I am using IBDataBase and IBTablefor the DBGrid and IBquery.

When I disconnect the IBDatabaseand reconnect then I get the updated data. Isn't there a better way?


回答1:


Most probably you have two transactions, one to populate the grid and another to make changes in the subform.

Then, the grid's transaction is probably

  • set up as SNAPSHOT kind, not READ COMMITTED kind
  • is not restarted after the subform's tx "commits" changed data

That way this transaction refuses to see changes introduced after it was started. But when you re-connect to the database you implicitly roll-back that tx and start another newer grid's tx.

If so, you would have to either change the grid's tx to RC kind (proving it would not break anything else in the form) or manually restart that transaction to let it see the newer data.



来源:https://stackoverflow.com/questions/51288432/dbgrid-data-not-updated-until-restarting-app-or-db-connection

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!