我使用的是Microsoft Sync Framework,但它在客户端配置中出错。错误是"登录失败。登录来自不受信任的域,不能与Windows身份验证一起使用"任何人都可以帮助我。我从客户端到服务器的数据库传输和我这边的SQL是SQL Server 2008,并希望在服务器上传数据,即SQl Server 2012。
SqlConnection clientConn = new SqlConnection(@"Data Source="CourierServices"; Catalog=CourierServices; Integrated Security=False;User ID=CourierServices;Password=Reset123");
SqlConnection serverConn = new SqlConnection(@"Data Source=Subhash-PC\SQLExpress; Initial Catalog=CourierServices; Integrated Security=True;User ID=sa;Password=Reset123");
private void btnGo_Click(object sender, EventArgs e)
{
ProvisionServer();
}
预配: -
public void ProvisionServer()
{
// define a new scope named MySyncScope
DbSyncScopeDescription scopeDesc = new DbSyncScopeDescription("MySyncScope");
// get the description of the CUSTOMER & PRODUCT table from SERVER database
DbSyncTableDescription cusTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("State", serverConn);
DbSyncTableDescription prodTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("City", serverConn);
DbSyncTableDescription ClientTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Client", serverConn);
DbSyncTableDescription ClientAddressTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("ClientAddress", serverConn);
DbSyncTableDescription ClientContactsTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("ClientContacts", serverConn);
DbSyncTableDescription TransactionTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("Transaction", serverConn);
DbSyncTableDescription TransactionDetailsTableDesc = SqlSyncDescriptionBuilder.GetDescriptionForTable("TransactionDetails", serverConn);
// add the table description to the sync scope definition
scopeDesc.Tables.Add(cusTableDesc);
scopeDesc.Tables.Add(prodTableDesc);
scopeDesc.Tables.Add(ClientTableDesc);
scopeDesc.Tables.Add(ClientAddressTableDesc);
scopeDesc.Tables.Add(ClientContactsTableDesc);
scopeDesc.Tables.Add(TransactionTableDesc);
scopeDesc.Tables.Add(TransactionDetailsTableDesc);
// create a server scope provisioning object based on the MySyncScope
SqlSyncScopeProvisioning serverProvision = new SqlSyncScopeProvisioning(serverConn, scopeDesc);
// skipping the creation of table since table already exists on server
serverProvision.SetCreateTableDefault(DbSyncCreationOption.Skip);
// start the provisioning process
serverProvision.Apply();
//MessageBox.Show("Server Successfully Provisioned");
ProvisionClient();
// Console.ReadLine();
}
ProvisionClient: -
public void ProvisionClient()
{
// create a connection to the client database
// SqlConnection clientConn = new SqlConnection(@"Data Source=Subhash-PC\SQLExpress; Initial Catalog=Courier; Integrated Security=True;User ID=sa;Password=Reset123");
// create a connection to the server database
// SqlConnection serverConn = new SqlConnection(@"Data Source=Subhash-PC\SQLExpress; Initial Catalog=CourierServices; Integrated Security=True;User ID=sa;Password=Reset123");
// get the description of SyncScope from the server database
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("MySyncScope", serverConn);
// create server provisioning object based on the SyncScope
SqlSyncScopeProvisioning clientProvision = new SqlSyncScopeProvisioning(clientConn, scopeDesc);
// starts the provisioning process
clientProvision.Apply();
//MessageBox.Show("Client Successfully Provisioned.");
}
ExecSync: -
public void ExecSync()
{
// create the sync orhcestrator
SyncOrchestrator syncOrchestrator = new SyncOrchestrator();
// set local provider of orchestrator to a sync provider associated with the
// MySyncScope in the client database
syncOrchestrator.LocalProvider = new SqlSyncProvider("MySyncScope", clientConn);
// set the remote provider of orchestrator to a server sync provider associated with
// the MySyncScope in the server database
syncOrchestrator.RemoteProvider = new SqlSyncProvider("MySyncScope", serverConn);
// set the direction of sync session to Upload and Download
syncOrchestrator.Direction = SyncDirectionOrder.UploadAndDownload;
// subscribe for errors that occur when applying changes to the client
((SqlSyncProvider)syncOrchestrator.LocalProvider).ApplyChangeFailed += new EventHandler<DbApplyChangeFailedEventArgs>(Program_ApplyChangeFailed);
// execute the synchronization process
SyncOperationStatistics syncStats = syncOrchestrator.Synchronize();
// print statistics
string Err = "";
Err = Err + "Data Uploaded Sucessfully" + Environment.NewLine;
//Err = Err + "Start Time: " + syncStats.SyncStartTime + "" + Environment.NewLine;
//Err = "Total Changes Uploaded: " + syncStats.UploadChangesTotal + "" + Environment.NewLine;
Err = Err + "Total Changes: " + syncStats.DownloadChangesTotal + "" + Environment.NewLine;
//Err = Err + "Complete Time: " + syncStats.SyncEndTime + "" + Environment.NewLine;
//MessageBox.Show(String.Empty);
MessageBox.Show(Err);
Console.ReadLine();
}
答案 0 :(得分:1)
这更多是SQL Server登录错误而不是SyncFx错误。同样,我可以看到您的连接字符串具有Integrated Security = true但您提供的内容看起来像SQL身份验证用户名和密码
答案 1 :(得分:0)
如果不是dbo,则需要SqlSyncDescriptionBuilder来指定ObjectSchema
像这样使用
DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope(“MySyncScope”,null, YourObjectSchemaName ,serverConn);