Handling Concurrency Errors in .NET framework

Print Code 128 in .NET framework Handling Concurrency Errors
8624 Handling Concurrency Errors
Encode Code 128C In .NET
Using Barcode generation for .NET framework Control to generate, create Code 128A image in VS .NET applications.
As we have just seen, rows may fail to synchronize; changes made at either end might not be acceptable at the other end Therefore, we add one last bit of functionality to our demo For each row that fails to synchronize, we need to determine which row it was, where it was rejected (server or client), and why it was rejected The possible reasons for why a row might fail to synchronize are specified by Microsoft in the ConflictType enumerator; see Table 84
Read Code128 In Visual Studio .NET
Using Barcode recognizer for VS .NET Control to read, scan read, scan image in .NET applications.
86 Using Data Synchronization Services
Barcode Generation In Visual Studio .NET
Using Barcode generation for Visual Studio .NET Control to generate, create bar code image in .NET framework applications.
TABLE 84: Synchronization Errors
Scan Barcode In VS .NET
Using Barcode scanner for Visual Studio .NET Control to read, scan read, scan image in Visual Studio .NET applications.
ConflictType
ANSI/AIM Code 128 Generator In C#.NET
Using Barcode generator for Visual Studio .NET Control to generate, create Code 128 Code Set B image in .NET framework applications.
ClientDeleteServerUpdate ClientInsertServerInsert ClientUpdateServerDelete ClientUpdateServerUpdate
Code 128 Code Set A Maker In Visual Studio .NET
Using Barcode encoder for ASP.NET Control to generate, create Code 128C image in ASP.NET applications.
Meaning
Making Code 128 Code Set C In VB.NET
Using Barcode creation for .NET framework Control to generate, create Code128 image in VS .NET applications.
The client deleted a row that the server updated The client and server both inserted a row that has the same primary key value The server deleted a row that the client updated The client and the server updated the same row
Draw Bar Code In .NET
Using Barcode printer for .NET Control to generate, create bar code image in .NET framework applications.
Note that ClientDeleteServerDelete is not an error Any scenario in which the client wanted the row deleted and the row is deleted is not an error The fact that the row was already deleted, and may have had different values in it from what the client thought it had, does not matter We start with the SyncAgent object; the object whose Synchronize method executes and monitors the entire synchronization The SyncAgent object holds references to two SyncProvider objects: one that it uses to communicate with the server and one that it uses to communicate with the client In our application, one is a SQL Server 2005 provider and one is a SQL Server CE provider During synchronization, whenever a row cannot be inserted, updated, or deleted, at either the client or the server, because of a currency conflict, the appropriate provider raises an ApplyChangeFailed event To process conflicts, we need to handle that event in our application To illustrate, we will detect failures that occur at the client; highly similar code would be used to detect server-side failures It is the SyncAgent s LocalProvider property object that will raise the ApplyChangeFailed event To make this event visible to IntelliSense, we need to cast the LocalProvider to the specific class of provider that will reside in the property at runtime; normally either SqlCeClientSyncProvider or DbServerClientSyncProvider Thus, our event signup code is:
GTIN - 13 Drawer In .NET
Using Barcode maker for .NET Control to generate, create EAN-13 image in VS .NET applications.
((SqlCeClientSyncProvider) (syncAgentLocalProvider)) ApplyChangeFailed += new EventHandler <ApplyChangeFailedEventArgs> (FormData_ApplyChangeFailed);
Barcode Creator In .NET Framework
Using Barcode creator for .NET framework Control to generate, create bar code image in VS .NET applications.
Synchronizing Mobile Data
Generating ECC200 In .NET
Using Barcode drawer for VS .NET Control to generate, create Data Matrix ECC200 image in .NET applications.
The actual handler is shown in Listing 814 The EventArgs that we are handed contains a Conflict object, which, in turn, contains the reason for the row being rejected and also the row itself The ConflictConflictType property contains the reason, while the ConflictClientChange property contains an untyped data table that holds the rejected row
ISBN - 10 Maker In .NET
Using Barcode drawer for .NET Control to generate, create ISBN - 13 image in .NET framework applications.
Listing 814: The Synchronization Error Handler
Bar Code Creation In Visual Studio .NET
Using Barcode maker for ASP.NET Control to generate, create barcode image in ASP.NET applications.
void FormData_ApplyChangeFailed( object sender, ApplyChangeFailedEventArgs e) { MessageBoxShow( stringFormat( "{1}{0}{2}{0}{0}" + "{3} {4}{0}{0}" + "{5}{0}{6}{0}", EnvironmentNewLine, "Conflict Type:", eConflictConflictTypeToString(), "CustomerID:", eConflictClientChangeRows[0] ["CustomerID"]ToString(), "CompanyName:", eConflictClientChangeRows[0] ["CompanyName"]ToString())); }
Bar Code Creation In Java
Using Barcode creator for Java Control to generate, create barcode image in Java applications.
Figure 833 shows the result from a scenario in which a row was inserted at the server concurrently with a row of the same primary key being inserted at the device
Data Matrix 2d Barcode Encoder In Java
Using Barcode maker for Java Control to generate, create Data Matrix ECC200 image in Java applications.
Figure 833: Displaying the Failed Row
Code 128 Code Set C Reader In .NET Framework
Using Barcode scanner for VS .NET Control to read, scan read, scan image in Visual Studio .NET applications.
86 Using Data Synchronization Services
DataMatrix Printer In Visual C#
Using Barcode generation for VS .NET Control to generate, create Data Matrix image in Visual Studio .NET applications.
Database Server Synchronization Services Server
Code 128 Generator In Java
Using Barcode maker for Java Control to generate, create Code 128 Code Set B image in Java applications.
To/From Figure 835 Client-side data changes Results of applying server-side data changes Server-side data changes Results of applying client-side data changes Control information (timestamps & client Ids) Less frequently: Snapshot data & metadata
Bar Code Encoder In VB.NET
Using Barcode creation for .NET Control to generate, create bar code image in .NET framework applications.
Data Store that supports MicrosoftSynchronization Change tracking objects and objects ADONET derived from For instance; SQL Server 2008 or MicrosoftSynchronization SQL Server 2005 with Objects wizard generated scripts applied
Scan UPC A In .NET
Using Barcode recognizer for .NET framework Control to read, scan read, scan image in VS .NET applications.
Figure 834: The Smart Device Application
This concludes our brief demonstration of developing a Data Synchronization Service Figures 834 and 835 diagram our resulting Smart Device application and Data Synchronization Service, respectively
8625 Some Closing Notes on Data Synchronization Services
As the need arises to add functionality to your solution, such as automatic conflict resolution or business logic, you can do so in any of several ways, three of which are mentioned here
Add logic to the client program, such as we did with our simple con-
flict detection logic This is a good solution for logic that is applicable to this client only Add logic to the service program This is a slightly unstable solution, as it may need to be redone if future modifications are generated by rerunning the Configure Data Synchronization Wizard Derive classes that contain your functionality from the MicrosoftSynchronization classes and use these classes in your service This is a good solution for logic that must be applied to the data regardless of the application that is manipulating that data In summary, Data Synchronization Services do the following: