How to check the availability of the TADODataSet in a dbgrid?

192 Views Asked by At

I use a DBGrid on my VCL Form. The grid is populated with the records, coming from a TADOConnection query. Semantically it looks like this:

  • Establish a connection to the database (SQL Server);
  • Fetch some records into a TADODataSet dataset;
  • Connect dataset with a TDataSource object;
  • Connect a DataSource object to the DBGrid.

My grid does the immediate post, which means the edited data is immediately posted to the database. Everything works fine, until the connection is closed (the network goes down, the laptop's lid is closed, etc.)

When the connection is lost, I cannot edit records in Grid, which causes EOleException (TCP PRovider: An existing connection was forcibly closed by the remote host) abd EDatabaseError (Communication link failure).

I want to catch the connectivity loss and re-establish connection, but I do not know how. I checked all data-specific events of the Grid, but the problem arises much earlier than any of the grid's events.

I believe that the problem is at the dataset level, but I don't know how to catch the exception. Does anyone know how to check dataset availability? Then I could write some code to re-connect. Something like this:

if not Assigned(DataSet) then
    //reconnect

Any assistance would be greatly appreciated.

0

There are 0 best solutions below