2010-02-16 77 views
1

我有一個SQL Server 2005框設置合併複製到SQL Server CE 3.0。出版物,出版商,分銷商和IIS都已經建立。SQL Server複製錯誤

在我的申請,我嘗試使用下面的代碼來同步數據庫:

//TODO: Change for production 
//*************************** 
string localDBPath = @"C:\Documents and Settings\Robert\Desktop\MyDB.sdf"; 
//*************************** 

SqlCeReplication replicator = new SqlCeReplication(); 
replicator.InternetUrl = "http://myWebServer/sqlcesa30.dll"; 
replicator.Publisher = "mySqlServer"; 
replicator.PublisherDatabase = "myDatabase"; 
replicator.PublisherSecurityMode = SecurityType.NTAuthentication; 
replicator.Publication = "myPublication"; 
replicator.Subscriber = Dns.GetHostName(); 
replicator.SubscriberConnectionString = @"Data Source=" + localDBPath; 

try 
{ 
    // Check if the database file already exists 
    if (!System.IO.File.Exists(localDBPath)) 
    { 
     // Add a new subscription and create the local database file 
     replicator.AddSubscription(AddOption.CreateDatabase); 
    } 

    // Transfer the initial snapshot of data if this is the first time this is called. 
    // Subsequent calls will transfer only the changes to the data. 
    replicator.Synchronize(); 
} 
catch (SqlCeException ex) 
{ 
    // Display any errors in message box 
    MessageBox.Show(ex.Message); 
} 
finally 
{ 
    // Dispose of the SqlCeReplication object, but don't drop the subscription 
    replicator.Dispose(); 
} 

不幸的是,該代碼將失敗,並出現以下錯誤消息「replicator.Synchronize」行:

未能通過提供的連接信息連接到SQL Server。 SQL Server不存在,訪問被拒絕,因爲IIS用戶不是SQL Server上的有效用戶,或者密碼不正確。

這個錯誤信息對我來說並不是很清楚,而且我沒有足夠的空間去尋找原因了。有任何想法嗎?

回答

1

確保代理帳戶在所有框上都是相同的用戶和密碼。

確保您正在調用正確的實例。

確保在涉及的所有機器上啓動代理。

檢查所有服務器上的sql事件日誌,看看哪個錯誤發生,這也可能縮小問題的範圍。

您還可以檢查是爲了確保你有設置正確:

http://msdn.microsoft.com/en-us/library/aa454892.aspx

這裏

同樣的問題,他必須正確添加實例名稱:

http://bytes.com/topic/sql-server/answers/611761-merge-replication-error-failure-connect-sql-server-provided-connection

檢查這些了太:

http://support.microsoft.com/kb/314783

http://support.microsoft.com/kb/319723

http://msdn2.microsoft.com/en-us/library/ms172357.aspx

再次確保您的實例是正確的: repl.Publisher = 「macnine名\實例名」

您還可以看看通過這個博客:

http://blogs.msdn.com/sql_protocols/archive/2005/09/28/474698.aspx

0

消息來自您的IIS複製插件:// MyWebServer的/ sqlcesa30.dll。當它試圖連接到發佈者時,它找不到它。發佈者被命名爲'mySqlServer',但顯然myWebServer無法訪問它。這可能是名稱問題(拼寫錯誤),防火牆問題(SQL端口被阻止),IPSEC問題,配置問題(SQL不會監聽遠程連接)等等。遵循myWeServer和mySqlServer之間的常規SQL Server連接故障排除步驟。