Dotmim.Sync icon indicating copy to clipboard operation
Dotmim.Sync copied to clipboard

Sync two sql server databases not working properly?

Open HunarAA opened this issue 2 years ago • 9 comments

I am using the framework to sync to sql server databases one is the localdb and the other one is on the cloud with WinForms application. I use the code below to do the sync operation

                 `string constring = @"Data Source= " + Properties.Settings.Default.Server + " ; Database = " + 
                 Properties.Settings.Default.Database + " ; User Id = " + Properties.Settings.Default.User_Name + "; Password = " + 
                 Properties.Settings.Default.Password + "; Encrypt=True; TrustServerCertificate=True; 
                MultipleActiveResultSets=True";

                string connect = @"Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=db_file1;Integrated 
                Security=SSPI;AttachDBFilename= " + Properties.Settings.Default.dbFilePath + "";

                SqlSyncProvider serverProvider = new SqlSyncProvider(connect);
                SqlSyncProvider clientProvider = new SqlSyncProvider(constring);

                SyncAgent agent = new SyncAgent(clientProvider, serverProvider, new string[] { "customers_tbl", "installments_tbl", 
               "items_tbl", "prod_disabled_zone_tbl", "products_tbl", "recipient_tbl", "returned_tbl", "substitutions_tbl", 
                "users_activity_tbl", "users_tbl", "zones_tbl" });

                  var syncContext = await agent.SynchronizeAsync();`

two to three months ago the operation was working properly but now each time I want to do sync operation I get different king of warnings and errors. Some of them stops the sync entirely while others does not stop sync operation but the it syncs a small number of records out of a large number of records. some of the errors and warnings I get: 1- "the command execution can not procced due to a pending a synchronous already in progress". 2- "procedure of function customers_tbl_changes has too many arguments specified". 3- "connection can not be changed while async operation is in progress". 4- "value cannot be null" 5- "the server failed to resume the transaction desc:3f00000002".

HunarAA avatar May 23 '22 11:05 HunarAA

Did you changed your schema since you are using DMS ? If yes, you should Deprovision and Provision again, to generate the new metadatas correctly (stored proc, triggers and so on ...)

Are you using the last version ?

Mimetis avatar May 23 '22 12:05 Mimetis

Yes the schema has a little changes. How can I add Deprovision and Provision to my existing code?

Now I have updated it to newest version which I think 0.9.4. The old version was 0.6.0

HunarAA avatar May 23 '22 13:05 HunarAA

If you are in test mode, just restart from scratch, it will be easier If you are in production, call the DeprovisionAsync() method on both side, Then Call ProvisionAsync() on both side

Mimetis avatar May 24 '22 07:05 Mimetis

I am in production mode but rather I did delete all triggers, procs, and tracking tables from both sides. Then, I used generate script - data only feature of SQL Server to export the data from server and import it into each client. One thing that I notice, when the connection is slow and you have a large number of records to be synced it faces timeout problem. Could you suggest a way to deal with this, please?

HunarAA avatar May 24 '22 08:05 HunarAA

Did you tried to set a batch size low ? like 1000 ?

Mimetis avatar Jul 18 '22 17:07 Mimetis

Where to set the batch size in the code?

HunarAA avatar Jul 23 '22 17:07 HunarAA

SyncOptions on the client side

Mimetis avatar Jul 23 '22 18:07 Mimetis

https://dotmimsync.readthedocs.io/Configuration.html#batch-mode

Mimetis avatar Jul 24 '22 21:07 Mimetis

Thanks a lot. I will try it and let you know.

HunarAA avatar Jul 25 '22 06:07 HunarAA