S. S. Rawat
S. S. Rawat

Reputation: 6121

Error throw in Sync Framework

I'm using Microsoft Sync Framework, but It give a error in client provision Error is "Login failed. The login is from an untrusted domain and cannot be used with Windows authentication" Can any one help me in this. My database transfer from client to server and sql in my side is SQL server 2008 and want to upload data in server i.e 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();

}

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();
        }

Upvotes: 0

Views: 634

Answers (2)

Michael Rajesh
Michael Rajesh

Reputation: 76

SqlSyncDescriptionBuilder is needed to specify ObjectSchema if it's not dbo

Use like this

DbSyncScopeDescription scopeDesc = SqlSyncDescriptionBuilder.GetDescriptionForScope("MySyncScope",null, YourObjectSchemaName , serverConn);

Upvotes: 0

JuneT
JuneT

Reputation: 7860

that's more of a SQL Server login error rather than a SyncFx error. likewise, i can see your connection string has Integrated Security=true but you're providing what looks like a SQL Authentication username and password

Upvotes: 1

Related Questions