Click here to Skip to main content
15,892,809 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
What I Want To Do :

i have a database with tables :
Items
ItemsBarcodes
Invoices
InvoiceDetails
--------------
the same database exists on server A and server B
--------------
only applications working on server A are allowed to add/modify rows to items and itemsBarcodes tables
--------------
i need a way to programatically send a file from application working on sever A that contains the added/modified data to the application that works on server B so that it can update the items and itemsBarcodes datatables

How I am Currently Doing It

1-i export the data from server A to Files like this :

VB
Try
            strm = Nothing

            strm = New FileStream(ItemsFileName, FileMode.OpenOrCreate)
            srItems.Serialize(strm, ds.Items)
            strm.Close()
            strm = Nothing

            strm = New FileStream(ItemsACFileName, FileMode.OpenOrCreate)
            srItemsAc.Serialize(strm, ds.ItemsAC)
            strm.Close()
            strm = Nothing

            strm = New FileStream(ItemsTagFileName, FileMode.OpenOrCreate)
            srItemsTag.Serialize(strm, ds.ItemsTag)
            strm.Close()
            strm = Nothing

            strm = New FileStream(BarcodesFileName, FileMode.OpenOrCreate)
            srBarcodes.Serialize(strm, ds.Barcodes)
            strm.Close()
            frmBase.ntfy.ShowBalloonTip(5000, "Done", "Items Count = " & ds.Items.Count, ToolTipIcon.Info)
        Catch ex As Exception
            frmBase.ntfy.ShowBalloonTip(5000, "Error", ex.Message, ToolTipIcon.Error)
        End Try


2-the i try to load the data back at server B like this :

Dim ds2 As New UltimatePharmaDataSet
VB
Try

           strm = Nothing
           strm = New FileStream(ItemsFileName, FileMode.OpenOrCreate)
           source = "Items"
           ds2.ReadXml(strm)
           strm.Close()


           strm = Nothing
           strm = New FileStream(ItemsACFileName, FileMode.OpenOrCreate)
           source = "ItemsAC"
           ds2.ReadXml(strm)
           strm.Close()


           strm = Nothing
           strm = New FileStream(ItemsTagFileName, FileMode.OpenOrCreate)
           source = "ItemsTag"
           ds2.ReadXml(strm)
           strm.Close()


           strm = Nothing
           strm = New FileStream(BarcodesFileName, FileMode.OpenOrCreate)
           source = "Barcodes"
           ds2.ReadXml(strm)
           strm.Close()
           source = ""

           For Each r As UltimatePharmaDataSet.ItemsRow In ds2.Items
               source = "Items" & r.ItemName
               If ds.Items.FindByItemID(r.ItemID) Is Nothing Then

                   r.SetAdded()
               Else

                   r.SetModified()


               End If
               r.EndEdit()
           Next

           For Each r As UltimatePharmaDataSet.BarcodesRow In ds2.Barcodes
               source = "Barcodes" & r.ItemsRow.ItemName & " " & r.Barcode
               If ds.Barcodes.FindByItemIDBarcode(r.ItemID, r.Barcode) Is Nothing Then

                   r.SetAdded()
               End If
               r.EndEdit()
           Next
           source = ""
           tadMngr.UpdateAll(ds2)
           frmBase.ntfy.ShowBalloonTip(5000, "Done", "Items Count = " & ds2.Items.Count, ToolTipIcon.Info)
       Catch ex As Exception
           frmBase.ntfy.ShowBalloonTip(5000, "Error", ex.Message & source, ToolTipIcon.Error)
       Finally
           strm.Close()
       End Try


where ds represents the original dataset on server B
and ds2 is the dataset read from the files sent from server A

The Problem Is :
when the tadMngr ( the TableAdapterManager ) tries to updateAll(ds2)
i get the error message :
concurrency violation the updateCommand affected 0 of the expected 1 record

i used SQL profiler to find out which rows cause the error
turns out only rows modified in server A or rows that have related rows modified raise this error

the error message is gone after i ignored those rows
but that is not the solution at all

--------------------
can any body help by pointing out what's wrong with my method or point me in the direction of a better method to achieve the same goal ?

thanks every body
Posted
Updated 11-Apr-14 10:17am
v2
Comments
CHill60 12-Apr-14 16:53pm    
Any particular reason why you have two copies of the database? Synchronisation of data is too big a subject to cover here. If you had a single database you could limit what apps can update what based on roles and permissions instead
Ahmad_kelany 12-Apr-14 18:07pm    
There is two copies because the application functionality is needed in two different places remote from each other ..and on the other hand i am not familiar with other methods to achieve this goal
CHill60 13-Apr-14 4:44am    
Fair enough. Do any of the suggestions here[^] help - I'm not posting a solution so as to keep your question open for others to chip in
Ahmad_kelany 13-Apr-14 23:51pm    
Thanks Very Much
i will try studying those solutions and pick one that fills my needs
syed shanu 13-Apr-14 21:35pm    
Is this both Server has Links.means can server A communicate to Serrver B and vise versa.For example Server A has actual table where you store all the updated informations.use Status Field for Example record with Status I is new Inserted,U for updated d for Deleted and Use C for completed .Create one backgrounbd application In server b its simple form with timer always check for the Server A table and select all the I,U,D status data from server a and for I insert the record in ur table and for U update and d you can delete the record once you done that change the status of each recourds in Server A to 'C'.You can use Linked server to communicate both servers.

1 solution

If these are SQL Server databases, use that server's built in replication methods[^]?
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900