SqlCeReplication repl = null; try { // Create SqlCeReplication instance // repl = new SqlCeReplication(); repl.InternetUrl = "http://www.adventure-works.com/sqlmobile/sqlcesa30.dll"; repl.InternetLogin = "MyInternetLogin"; repl.InternetPassword = "<password>"; repl.Publisher = "MyPublisher"; repl.PublisherDatabase = "MyPublisherDatabase"; repl.PublisherLogin = "MyPublisherLogin"; repl.PublisherPassword = "<password>"; repl.Publication = "MyPublication"; repl.Subscriber = "MySubscriber"; repl.SubscriberConnectionString = "Data Source=MyDatabase.sdf"; // Mark the subscription for reinitialization with Upload first // repl.ReinitializeSubscription(true); //必须保证订阅存在,否则会出现错误 // Synchronize to the SQL Server to populate the Subscription // repl.Synchronize(); } catch (SqlCeException) { // Handle errors here } finally { // Dispose the repl object // repl.Dispose(); }