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 :
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
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