.NET remoting

DataWindow synchronization

In a conventional client/server application, where database updates are initiated by a single application running on a client machine, the DataWindow server can manage DataWindow state information for you automatically. In an application that uses .NET remoting, the situation is somewhat different. Because application components are partitioned between the client and the server, you need to write logic to ensure that the data buffers and status flags for the DataWindow control on the client are synchronized with those for the DataStore on the server.

DataWindow .NET provides four methods that support .NET remoting for DataWindow controls and DataStores:

Although these methods are most useful in distributed applications, they can also be used in nondistributed applications where multiple DataWindow controls or DataStores must be synchronized.

Moving DataWindow buffers and status flags

To synchronize a DataWindow control on the client with a DataStore on the server, move the DataWindow data buffers and status flags back and forth between the client and the server whenever changes occur. The procedures for doing this are essentially the same whether the source of the changes resides on the client or the server.

To apply complete state information from one DataWindow control or DataStore to another, you need to:

  1. Invoke the GetFullState method to capture the current state of the source DataWindow or DataStore.

  2. Invoke the SetFullState method to apply the state of the source DataWindow or DataStore to the target.

To apply changes from one DataWindow control or DataStore to another, you need to:

  1. Invoke the GetChanges method to capture changes from the source DataWindow or DataStore.

  2. Invoke the SetChanges method to apply changes from the source DataWindow or DataStore to the target.

NoteSetChanges can be applied to an empty DataWindow control or DataStore You can call SetChanges to apply changes to an empty DataWindow control or DataStore. The target DataWindow control does not need to contain a result set from a previous retrieval operation. However, the DataWindow control must have access to the DataWindow definition. This means that you need to assign the DataWindow object to the target DataWindow control before calling SetChanges.

DataWindow state is stored in blobs

When you call GetFullState, the DataWindow server returns DataWindow state information in a DataWindowFullState object that inherits from the DataWindow Blob class. When you call GetChanges, state information is returned in a DataWindowChanges object that inherits from Blob. These objects support the ISerializable interface for use in .NET remoting applications.

This function in a client console application calls GetFullState, stores the state of the DataWindow object in a DataWindowFullState object, and writes progress to the console:

public DataWindowFullState GetDwData()
{
   Console.WriteLine("GetDwData() called");
   ds_1.DataWindowObject = "d_dept_grid";
   ds_1.SetTransaction(sqlca);
   
   DataWindowFullState FullState = null;
   try
   {
      ds_1.Retrieve();
      FullState = ds_1.GetFullState();

      Console.WriteLine("Retrieve Succeeded ");
   }
   catch (Sybase.DataWindow.DbErrorException ex)
   {
      Console.WriteLine("DbErrorException on Retrieve"
           + ex.SqlErrorText );
   }
   return FullState;
}

The DataWindowFullState object returned from GetFullState provides everything required to recreate the DataWindow, including the data buffers, status flags, and complete DataWindow specification. The DataWindowChanges object returned from GetChanges provides data buffers and status flags for changed and deleted rows only.

NoteDataWindowFullState and DataWindowChanges do not support Web services DataWindowFullState and DataWindowChanges cannot be used in a Web service because some of their members are internal or protected and therefore cannot be serialized using XML serialization.

Synchronizing after UpdateData

When called without arguments, the UpdateData method resets the update flags after a successful update. Therefore, when you call the UpdateData method on the server, the status flags are automatically reset for the server DataStore. However, the update flags for the corresponding client DataWindow control are not reset. Therefore, if the UpdateData method on the server DataStore succeeds, call ResetUpdateStatus on the client DataWindow to reset the flags.

One source, one target

You can synchronize a single source DataWindow control or DataStore with a single target DataWindow control or DataStore. Do not try to synchronize a single source with multiple targets, or vice versa.