共用方式為


SqlCeReplication 類別

初始化 SqlCeReplication 物件的新執行個體。如需有關 SQL Server 複寫的詳細資訊,請參閱《SQL Server 線上叢書》。如需有關 SQL Server Compact 3.5 合併式複寫的詳細資訊,請參閱《SQL Server Compact 3.5 線上叢書》。

命名空間:  System.Data.SqlServerCe
組件:  System.Data.SqlServerCe (在 System.Data.SqlServerCe.dll 中)

語法

'宣告
Public NotInheritable Class SqlCeReplication _
    Implements IDisposable
'用途
Dim instance As SqlCeReplication
public sealed class SqlCeReplication : IDisposable
public ref class SqlCeReplication sealed : IDisposable
[<SealedAttribute>]
type SqlCeReplication =  
    class
        interface IDisposable
    end
public final class SqlCeReplication implements IDisposable

備註

SQL Server Compact 3.5 目前並未最佳化,無法當做網站的資料庫。依預設,在 SQL Server Compact 3.5 中會封鎖從 ASP.NET 連接之應用程式的連線。SQL Server Compact 3.5 最適合做為應用程式中的內嵌資料庫。使用 SQL Server Compact 3.5 做為網站的資料庫需要支援多使用者與並行資料變更。這可能會造成效能問題。因此,並不支援這些狀況。其他版本的 SQL Server (包括 SQL Server 2005 Express Edition 和更新版本) 都已最佳化,可以當做網站的資料庫。

SQL Server Compact 3.5 可以在使用 ASP.NET 建立 SQL Server Compact 3.5 資料庫 (適用於同步處理案例) 的應用程式案例中搭配 ASP.NET 使用。使用下列程式碼以變更 SQL Server Compact 3.5 的預設行為,以便在 ASP.NET 中運作。

AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true)

範例

下列範例會示範如何同步處理 SQL Server Compact 3.5「訂閱者」與 SQL Server「發行者」之間的資料。系統會建立SqlCeReplication 物件,並設定 SqlCeReplication 物件的多個屬性,然後再呼叫 Synchronize 方法。

Dim repl As SqlCeReplication = Nothing

Try
    ' Instantiate and configure SqlCeReplication object
    '
    'NOTE: when possible, prompt users to enter security 
    'credentials at runtime. If you store credentials in a file, 
    'you must secure the file to prevent unauthorized access.
    '
    repl = New SqlCeReplication()
    repl.InternetUrl = "https://www.adventure-works.com/sqlce/sqlcesa35.dll"
    repl.InternetLogin = "MyInternetLogin"
    repl.InternetPassword = "<enterStrongPassword>"
    repl.Publisher = "MyPublisher"
    repl.PublisherDatabase = "MyPublisherDatabase"
    repl.PublisherLogin = "MyPublisherLogin"
    repl.PublisherPassword = "<enterStrongPassword>"
    repl.Publication = "MyPublication"
    repl.Subscriber = "MySubscriber"
    repl.SubscriberConnectionString = "Data Source=MyDatabase.sdf"

    ' Create the local SQL Mobile Database subscription
    '
    repl.AddSubscription(AddOption.CreateDatabase)

    ' Synchronize to the SQL Server to populate the Subscription 
    '
    repl.Synchronize()
Catch
    ' Handle errors here
    '
Finally
    ' Dispose the repl object
    '
    repl.Dispose()
End Try
SqlCeReplication repl = null;

try
{
    // Instantiate and configure SqlCeReplication object
    //
    //NOTE: when possible, prompt users to enter security 
    //credentials at runtime. If you store credentials in a file, 
    //you must secure the file to prevent unauthorized access.
    //
    repl = new SqlCeReplication();
    repl.InternetUrl = "https://www.adventure-works.com/sqlce/sqlcesa35.dll";
    repl.InternetLogin = "MyInternetLogin";
    repl.InternetPassword = "<enterStrongPassword>";
    repl.Publisher = "MyPublisher";
    repl.PublisherDatabase = "MyPublisherDatabase";
    repl.PublisherLogin = "MyPublisherLogin";
    repl.PublisherPassword = "<enterStrongPassword>";
    repl.Publication = "MyPublication";
    repl.Subscriber = "MySubscriber";
    repl.SubscriberConnectionString = "Data Source=MyDatabase.sdf";

    // Create a local SQL Mobile Database subscription
    //
    repl.AddSubscription(AddOption.CreateDatabase);

    // Synchronize to the SQL Server database
    //
    repl.Synchronize();
}
catch (SqlCeException)
{
    // Handle errors here
    //
}
finally
{
    // Dispose the repl object
    //
    repl.Dispose();
}

繼承階層

System. . :: . .Object
  System.Data.SqlServerCe..::..SqlCeReplication

執行緒安全性

Any public static (Shared in Microsoft Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

請參閱

參考

SqlCeReplication 成員

System.Data.SqlServerCe 命名空間