SqlCeClientSyncProvider Class
Abstracts a client synchronization provider for SQL Server Compact that communicates with the client and shields the synchronization agent from the specific implementation of the client database.
Inheritance Hierarchy
System.Object
Microsoft.Synchronization.SyncProvider
Microsoft.Synchronization.Data.ClientSyncProvider
Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider
Namespace: Microsoft.Synchronization.Data.SqlServerCe
Assembly: Microsoft.Synchronization.Data.SqlServerCe (in Microsoft.Synchronization.Data.SqlServerCe.dll)
Syntax
'Declaration
Public Class SqlCeClientSyncProvider _
Inherits ClientSyncProvider
'Usage
Dim instance As SqlCeClientSyncProvider
public class SqlCeClientSyncProvider : ClientSyncProvider
public ref class SqlCeClientSyncProvider : public ClientSyncProvider
type SqlCeClientSyncProvider =
class
inherit ClientSyncProvider
end
public class SqlCeClientSyncProvider extends ClientSyncProvider
The SqlCeClientSyncProvider type exposes the following members.
Constructors
Name | Description | |
---|---|---|
![]() |
SqlCeClientSyncProvider() | Initializes a new instance of the SqlCeClientSyncProvider class by using default values. |
![]() |
SqlCeClientSyncProvider(String) | Initializes a new instance of the SqlCeClientSyncProvider class by using a connection string parameter. |
![]() |
SqlCeClientSyncProvider(String, Boolean) | Initializes a new instance of the SqlCeClientSyncProvider class by using connection string and database creation parameters. |
Top
Properties
Name | Description | |
---|---|---|
![]() |
ClientId | Gets or sets the GUID that Sync Framework uses to identify the client database. (Overrides ClientSyncProvider.ClientId.) |
![]() |
ConflictResolver | Gets a SyncConflictResolver object for the client synchronization provider, which determines what action to take when a conflict occurs. |
![]() |
Connection | Gets the IDbConnection object that is used to connect to the client database. |
![]() |
ConnectionString | Gets or sets the string that is used to connect to the client database. |
![]() |
CreateDatabaseIfNotExists | Gets or sets whether to create the client database if it does not exist. |
![]() |
RetentionInDays | Gets or sets the number of days that change-tracking metadata is stored in a SQL Server Compact database. |
Top
Methods
Name | Description | |
---|---|---|
![]() |
AcceptChanges(IEnumerable<String>) | Updates tracking metadata for the specified tables so that pending changes for the specified tables are not uploaded during the next synchronization. |
![]() |
AcceptChanges(String) | Updates tracking metadata so that pending changes for the specified table are not uploaded during the next synchronization. |
![]() |
AcceptChanges(IEnumerable<String>, SyncAnchor) | Updates tracking metadata up to the specified anchor point so that pending changes for the specified tables at the client are not uploaded during the next synchronization. |
![]() |
AcceptChanges(String, SyncAnchor) | Updates tracking metadata up to the specified anchor point so that pending changes for the specified table at the client are not uploaded during the next synchronization. |
![]() |
ApplyChanges(IEnumerable<String>, DataSet, SyncAnchor) | Applies inserts, updates, and deletes for a synchronization group to the client database when given table names, a data set, and server anchor parameters. |
![]() |
ApplyChanges(String, DataSet, SyncAnchor) | Applies inserts, updates, and deletes for a synchronization group to the client database when given a table name, a data set, and server anchor parameters. |
![]() |
ApplyChanges(SyncGroupMetadata, DataSet, SyncSession) | Applies inserts, updates, and deletes for a synchronization group to the client database when given group metadata, a data set, and synchronization session parameters. (Overrides ClientSyncProvider.ApplyChanges(SyncGroupMetadata, DataSet, SyncSession).) |
![]() |
BeginTransaction | Called by the SyncAgent to begin a transaction. This allows the agent to commit a set of changes as an atomic unit. (Overrides ClientSyncProvider.BeginTransaction(SyncSession).) |
![]() |
CreateSchema | Creates the table schema in the client database if the schema does not exist. (Overrides ClientSyncProvider.CreateSchema(SyncTable, SyncSchema).) |
![]() |
Dispose() | Releases all resources that are used by the SqlCeClientSyncProvider. (Overrides ClientSyncProvider.Dispose().) |
![]() |
Dispose(Boolean) | Releases the unmanaged resources that are used by the SqlCeClientSyncProvider and optionally releases the managed resources. |
![]() |
EndTransaction | Called by the SyncAgent to end a transaction. This allows the agent to commit a set of changes as an atomic unit. (Overrides ClientSyncProvider.EndTransaction(Boolean, SyncSession).) |
![]() |
Equals | (Inherited from Object.) |
![]() |
Finalize | Is the destructor for SqlCeClientSyncProvider. (Overrides Object.Finalize().) |
![]() |
GetChanges(IEnumerable<String>) | Gets inserts, updates, and deletes from the specified tables at the client that occurred since the last time Synchronize or AcceptChanges was called. |
![]() |
GetChanges(String) | Gets inserts, updates, and deletes from the specified table at the client that occurred since the last time Synchronize or AcceptChanges was called. |
![]() |
GetChanges(SyncGroupMetadata, SyncSession) | Gets inserts, updates, and deletes for the specified synchronization group and session that occurred at the client since the last time Synchronize or AcceptChanges was called. (Overrides ClientSyncProvider.GetChanges(SyncGroupMetadata, SyncSession).) |
![]() |
GetHashCode | (Inherited from Object.) |
![]() |
GetTableReceivedAnchor | Gets a SyncAnchor object that contains the time when the last change was received from the server. (Overrides ClientSyncProvider.GetTableReceivedAnchor(String).) |
![]() |
GetTableSentAnchor | Gets a SyncAnchor object that contains the time when the last change was sent from the client. (Overrides ClientSyncProvider.GetTableSentAnchor(String).) |
![]() |
GetType | (Inherited from Object.) |
![]() |
MemberwiseClone | (Inherited from Object.) |
![]() |
OnApplyChangeFailed | Raises the ApplyChangeFailed event. |
![]() |
OnApplyingChanges | Raises the ApplyingChanges event. |
![]() |
OnChangesApplied | Raises the ChangesApplied event. |
![]() |
OnChangesSelected | Raises the ChangesSelected event. |
![]() |
OnCreatingSchema | Raises the CreatingSchema event. |
![]() |
OnInitialized | Raises the initialized event. |
![]() |
OnSchemaCreated | Raises the SchemaCreated event. |
![]() |
OnSelectingChanges | Raises the SelectingChanges event. |
![]() |
OnSyncProgress | Raises the SyncProgress event. |
![]() |
SetTableReceivedAnchor | Sets a SyncAnchor object that contains the time that the last change was received from the server. (Overrides ClientSyncProvider.SetTableReceivedAnchor(String, SyncAnchor).) |
![]() |
SetTableSentAnchor | Sets a SyncAnchor object that contains the time when the last change was sent from the client. (Overrides ClientSyncProvider.SetTableSentAnchor(String, SyncAnchor).) |
![]() |
ToString | (Inherited from Object.) |
Top
Events
Name | Description | |
---|---|---|
![]() |
ApplyChangeFailed | Occurs after a row could not be applied at the client. |
![]() |
ApplyingChanges | Occurs before changes are applied at the client for a synchronization group. |
![]() |
ChangesApplied | Occurs after all changes are applied at the client for a synchronization group. |
![]() |
ChangesSelected | Occurs after all changes to be applied to the server for a synchronization group are selected from the client. |
![]() |
CreatingSchema | Occurs before the schema is created at the client for each table. |
![]() |
SchemaCreated | Occurs after the schema is created at the client for each table. |
![]() |
SelectingChanges | Occurs before all changes to be applied to the server for a synchronization group are selected from the client. |
![]() |
SyncProgress | Occurs during the selection and application of changes for a synchronization group at the client. |
Top
Remarks
The principal activities of the client synchronization provider are as follows:
Stores information about tables on the client that are enabled for synchronization.
Retrieves changes that occurred in the client database since the last synchronization.
Applies incremental changes to the client database.
Detects conflicting changes.
Examples
The following code example creates a class that derives from SqlCeClientSyncProvider. The class creates a connection to the client database and handles several common events, including schema creation in the client database. To view this code in the context of a complete example, see How to: Work with Events and Program Business Logic.
public class SampleClientSyncProvider : SqlCeClientSyncProvider
{
public SampleClientSyncProvider()
{
//Specify a connection string for the sample client database.
Utility util = new Utility();
this.ConnectionString = Utility.ConnStr_SqlCeClientSync;
//Log information for the following events.
this.SchemaCreated += new EventHandler<SchemaCreatedEventArgs>(EventLogger.LogEvents);
this.ChangesSelected += new EventHandler<ChangesSelectedEventArgs>(EventLogger.LogEvents);
this.ChangesApplied += new EventHandler<ChangesAppliedEventArgs>(EventLogger.LogEvents);
this.ApplyChangeFailed += new EventHandler<ApplyChangeFailedEventArgs>(EventLogger.LogEvents);
//Use the following events to fix up schema on the client.
//We use the CreatingSchema event to change the schema
//by using the API. We use the SchemaCreated event
//to change the schema by using SQL.
//Note that both schema events fire for the Customer table,
//even though we already created the table. This allows us
//to work with the table at this point if we have to.
this.CreatingSchema += new EventHandler<CreatingSchemaEventArgs>(SampleClientSyncProvider_CreatingSchema);
this.SchemaCreated += new EventHandler<SchemaCreatedEventArgs>(SampleClientSyncProvider_SchemaCreated);
}
private void SampleClientSyncProvider_CreatingSchema(object sender, CreatingSchemaEventArgs e)
{
string tableName = e.Table.TableName;
if (tableName == "Customer")
{
//Set the RowGuid property because it is not copied
//to the client by default. This is also a good time
//to specify literal defaults with .Columns[ColName].DefaultValue,
//but we will specify defaults like NEWID() by calling
//ALTER TABLE after the table is created.
e.Schema.Tables["Customer"].Columns["CustomerId"].RowGuid = true;
}
if (tableName == "OrderHeader")
{
e.Schema.Tables["OrderHeader"].Columns["OrderId"].RowGuid = true;
}
}
private void SampleClientSyncProvider_SchemaCreated(object sender, SchemaCreatedEventArgs e)
{
string tableName = e.Table.TableName;
Utility util = new Utility();
//Call ALTER TABLE on the client. This must be done
//over the same connection and within the same
//transaction that Sync Framework uses
//to create the schema on the client.
if (tableName == "Customer")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "Customer");
}
if (tableName == "OrderHeader")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderHeader");
}
if (tableName == "OrderDetail")
{
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderDetail");
}
}
}
Public Class SampleClientSyncProvider
Inherits SqlCeClientSyncProvider
Public Sub New()
'Specify a connection string for the sample client database.
Dim util As New Utility()
Me.ConnectionString = Utility.ConnStr_SqlCeClientSync
'Log information for the following events.
AddHandler Me.SchemaCreated, AddressOf EventLogger.LogEvents
AddHandler Me.ChangesSelected, AddressOf EventLogger.LogEvents
AddHandler Me.ChangesApplied, AddressOf EventLogger.LogEvents
AddHandler Me.ApplyChangeFailed, AddressOf EventLogger.LogEvents
'Use the following events to fix up schema on the client.
'We use the CreatingSchema event to change the schema
'by using the API. We use the SchemaCreated event
'to change the schema by using SQL.
'Note that both schema events fire for the Customer table,
'even though we already created the table. This allows us
'to work with the table at this point if we have to.
AddHandler Me.CreatingSchema, AddressOf SampleClientSyncProvider_CreatingSchema
AddHandler Me.SchemaCreated, AddressOf SampleClientSyncProvider_SchemaCreated
End Sub 'New
Private Sub SampleClientSyncProvider_CreatingSchema(ByVal sender As Object, ByVal e As CreatingSchemaEventArgs)
Dim tableName As String = e.Table.TableName
If tableName = "Customer" Then
'Set the RowGuid property because it is not copied
'to the client by default. This is also a good time
'to specify literal defaults with .Columns[ColName].DefaultValue,
'but we will specify defaults like NEWID() by calling
'ALTER TABLE after the table is created.
e.Schema.Tables("Customer").Columns("CustomerId").RowGuid = True
End If
If tableName = "OrderHeader" Then
e.Schema.Tables("OrderHeader").Columns("OrderId").RowGuid = True
End If
End Sub 'SampleClientSyncProvider_CreatingSchema
Private Sub SampleClientSyncProvider_SchemaCreated(ByVal sender As Object, ByVal e As SchemaCreatedEventArgs)
Dim tableName As String = e.Table.TableName
Dim util As New Utility()
'Call ALTER TABLE on the client. This must be done
'over the same connection and within the same
'transaction that Sync Framework uses
'to create the schema on the client.
If tableName = "Customer" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "Customer")
End If
If tableName = "OrderHeader" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderHeader")
End If
If tableName = "OrderDetail" Then
Utility.MakeSchemaChangesOnClient(e.Connection, e.Transaction, "OrderDetail")
End If
End Sub 'SampleClientSyncProvider_SchemaCreated
End Class 'SampleClientSyncProvider
Thread Safety
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.