0

I have developed a client/server application that uses a mySQL database as the database on the server. Now the app that will access the server will also have a database that will store the local data. For that I used a firebird database.

Now the app must update the local database, with records from the mySQL database, say once a day. Now the problem is, that I need to also change the record in the mySQL as soon as it has updated the firebird database, but when I want the app runs and I click the update button, I get the following error and no data gets updated to the firebird database as well:

database.exe raised exception class EDatabaseError with message 'tbStudent: Cannot modify a
read-only dataset'.

At the moment I'm running the mySQL via XAMMP on my localhost, and the firebird is also running on localhost. I'm developing with Delphi XE2

Edit: Sorry guys, it seems the question was not clear. For my mySQL connection I'm using the standard TSQLConnection, and TSQLTable components, and the queries uses TSQLQuery. So when I try and access the mySQL database with a TGrid for example, it gives me action is not allowed for unidirectional datasets. I cannot write to the TSQLTable, as it gives me the read-only dataset error. I tried looking at the components and there is no place to change them from read only to also grant write access. That is what I'm trying to figure out, how to grant write access

Japster
  • 985
  • 6
  • 19
  • 38

2 Answers2

0

I have managed to get an answer for the above mentioned problem. It took me some reading and I discovered the solution in a book named C++builder Database Development, by Bob Swart.

"All dbExpress datasets (TSQLDataset, TSQLTable, TSQLQuery and TSQLStoredProc - if returning a dataset) are very special, in that their contents is read-only and unidirectional. This means that you can read the records in a TSQLTable, but only from the first one to the last one, and you cannot make any changes to this data."

Since a TDBGrid can show more than one record at a time, it allows you to navigate from one record to another (and back), which is not allowed directly on a dbExpress dataset.

If we can transfer the contents of the dbExpress dataset to a TClientDataSet, then we can view and navigate all we want. And that solves my problem. It is a real noob mistake, but then again, I do still regard myself as a noob :-).

Japster
  • 985
  • 6
  • 19
  • 38
-1

I think the problem is that your dataset is not on edit mode.

How to Modify Field Values in TDataSetProvider.OnUpdateData

Take a look at the link below.

Community
  • 1
  • 1
JGutierrezC
  • 4,398
  • 5
  • 25
  • 42
  • This is wrong. The error message doesn't say the table is not in edit mode; it says it's a read-only table. They're not the same. – Ken White Sep 03 '13 at 00:14
  • @KenWhite It doesn't say the table is read-only, it says the **dataset** is, so to me - although I don't know Delphi - this answer seems on the right track, see also http://stackoverflow.com/questions/653350/delphi-clientdataset-read-only – Mark Rotteveel Sep 03 '13 at 07:58
  • @MarkRotteveel: The link you post specifically refers to a TClientDataSet, and I don't see a mention of that in-memory dataset anywhere in this question. It refers to a MySQL DB on the server and a Firebird DB on the local system. There's no mention of a CDS anywhere in the process. – Ken White Sep 03 '13 at 13:03
  • @KenWhite As I said, I don't know Delphi, but the error seems to be the same which - naively - leads me to think they have the same underlying cause. – Mark Rotteveel Sep 03 '13 at 13:31
  • 1
    @MarkRotteveel: Looks like KenWhite knows more than you what do you need... anyway, i don't know if you read in spanish, but this link (http://www.clubdelphi.com/foros/showthread.php?t=51217) points to the same issue and the final poster says that (after thanking everybody) he put the dataset on edit mode and that did the trick. – JGutierrezC Sep 03 '13 at 13:57
  • @JGutierrezC I am not the one who asked the question :) Just trying to help. – Mark Rotteveel Sep 03 '13 at 13:59
  • Sorry guys, it seems the question was not clear. For my mySQL connection I'm using the standard TSQLConnection, and TSQLTable components, and the queries uses TSQLQuery. So when I try and access the mySQL database with a TGrid for example, it gives me action is not allowed for unidirectional datasets. I cannot write to the TSQLTable, as it gives me the read-only dataset error. I tried looking at the components and there is no place to change them from read only to also grant write access. That is what I'm trying to figure out, how to grant write access. – Japster Sep 03 '13 at 14:12