SqlCeClientSyncProvider 클래스
클라이언트와 통신하며 동기화 에이전트가 클라이언트 데이터베이스를 특정 방식으로 구현하지 못하도록 차단하는 SQL Server Compact의 클라이언트 동기화 공급자를 추상화합니다.
네임스페이스: Microsoft.Synchronization.Data.SqlServerCe
어셈블리: microsoft.synchronization.data.sqlserverce.dll의 Microsoft.Synchronization.Data.SqlServerCe
구문
‘선언
<SuppressMessageAttribute("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")> _
<SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")> _
Public Class SqlCeClientSyncProvider
Inherits ClientSyncProvider
‘사용 방법
Dim instance As SqlCeClientSyncProvider
[SuppressMessageAttribute("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
[SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")]
public class SqlCeClientSyncProvider : ClientSyncProvider
[SuppressMessageAttribute(L"Microsoft.Maintainability", L"CA1506:AvoidExcessiveClassCoupling")]
[SuppressMessageAttribute(L"Microsoft.Naming", L"CA1706:ShortAcronymsShouldBeUppercase")]
public ref class SqlCeClientSyncProvider : public ClientSyncProvider
/** @attribute SuppressMessageAttribute("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling") */
/** @attribute SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase") */
public class SqlCeClientSyncProvider extends ClientSyncProvider
SuppressMessageAttribute("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")
SuppressMessageAttribute("Microsoft.Naming", "CA1706:ShortAcronymsShouldBeUppercase")
public class SqlCeClientSyncProvider extends ClientSyncProvider
주의
클라이언트 동기화 공급자가 수행하는 주요 작업은 다음과 같습니다.
동기화에 사용할 수 있는 클라이언트의 테이블에 대한 정보 저장
마지막 동기화 이후 클라이언트 데이터베이스에서 수행된 변경 내용 검색
클라이언트 데이터베이스에 증분 변경 내용 적용
충돌하는 변경 내용 감지
예제
다음 코드 예제에서는 SqlCeClientSyncProvider에서 파생되는 클래스를 만듭니다. 이 클래스는 클라이언트 데이터베이스에 대한 연결을 만들며 클라이언트 데이터베이스에서 스키마를 만드는 것과 같은 몇 가지 일반적인 이벤트를 처리합니다. 전체 예제의 맥락에서 이 코드를 보려면 방법: 이벤트 및 프로그램 비즈니스 논리 사용을 참조하십시오.
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
상속 계층 구조
System.Object
Microsoft.Synchronization.SyncProvider
Microsoft.Synchronization.Data.ClientSyncProvider
Microsoft.Synchronization.Data.SqlServerCe.SqlCeClientSyncProvider
스레드로부터의 안전성
이 유형의 모든 public static(Visual Basic의 경우 Shared ) 멤버는 스레드로부터 안전합니다. 인스턴스 멤버는 스레드로부터의 안전성이 보장되지 않습니다.
참고 항목
참조
SqlCeClientSyncProvider 멤버
Microsoft.Synchronization.Data.SqlServerCe 네임스페이스