开发者

How do I solve the "Cannot perform this operation on a closed dataset" with Borland Database Engine and a Delphi application? [closed]

It's difficul开发者_如何学Ct to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 11 years ago.

The application was working perfectly, until I edited the user database (*.dbf) in OpenOffice.org Calc. Now it gives me the above error about a closed dataset.


As per your own comment, you were unable to open the database file because it was corrupt. Thus, the error in your case meant not that you forgot to open it, but that your app cannot open the corrupt .dbf file.

Other not-so-obvious reasons why you might get this error, than the obvious thing that you failed to set the table Active property to true, include system or BDE configuration errors (ODBC or ADO, or other BDE runtime files missing or not configured) that are required to open the file


Error message says, that your dataset is not open. Seems you forgot to Open it or you Closed it somewhere.


If you run your application Delphi will restore the open or closed state that the dataset had in the Delphi form designer.

If there is an error Delphi can quitly drop this and close the dataset.
Also it's possible that you accidently closed the dataset in the designer, after with it no longer auto-opens on ptogram start.
When it's time to use the dataset you will get this error because the dataset is closed.

One option is to explicitly open the dataset in the FormCreate event and add error handling code there, this will allow you to see the error message and debug from there.

procedure TForm1.FormCreate(sender: TObject);
begin
  try
    MyDBFTable.Open;
  except on exception e do 
    WriteErrorToLogFile('Cannot open MyDBFTable, error is: ' + e.message);
    // or 
    //ShowMessage('Cannot open MyDBFTable, error is: ' + e.message);
  end; {try}
end;

I always do opening of datasets explicitly in FormCreate because this allows me to log any errors. If a client app has an exception it gets emailed to me automatically.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜