This morning I finally got my authors copy of the dot.net Magazin that I wrote an article on Microsoft Sync Framework. It’s in german, 7 pages long and you can buy it tomorrow.
Anyhow, I got an email this morning asking about one of the code listings and asking if there was anything different to do in VB.net. It’s been a while since I last did VB.net (I actually did more VB6 than VB.net) but I converted the sample from the magazine to VB.net. Just remember to reference Microsoft.Synchronization and Microsoft.Synchronization.Files.
(By the way I still haven’t got round to looking at CTP2 of the Sync Framework. All this stuff (and the article) applies to CTP1. Maybe there was a breaking change in CTP2 with regard to the FileSyncProvider. I must get round to looking at CTP2 a.s.a.p.)
Here is the code:
Imports Microsoft.Synchronization Imports Microsoft.Synchronization.Files Imports System.IO Module Module1 Sub Main() 'Define directories Dim _sourceDir As String = "c:\temp\1" Dim _destDir As String = "c:\temp\2" 'Define system ids Dim _sourceId As SyncId = New SyncId(New Guid("A4715EAF-341E-4ebf-90C3-71E8644CA6E8")) Dim _destId As SyncId = New SyncId(New Guid("FF766014-0DA4-401d-BDA1-0679326ECF96")) 'Exclude some patterns Dim _syncFilter As FileSyncScopeFilter = New FileSyncScopeFilter() _syncFilter.AttributeExcludeMask = FileAttributes.Hidden Or FileAttributes.System _syncFilter.FileNameExcludes.Add("DoNotCopy.txt") _syncFilter.SubdirectoryExcludes.Add("DoNotCopy") 'Setup options (makes sure files aren't deleted for ever) Dim _syncOptions As FileSyncOptions = FileSyncOptions.RecycleDeletes Or FileSyncOptions.RecycleOverwrites 'Do the sync Using _sourceProvider As FileSyncProvider = New FileSyncProvider(_sourceId, _sourceDir, _syncFilter, _syncOptions) Using _destinationProvider As FileSyncProvider = New FileSyncProvider(_destId, _destDir, _syncFilter, _syncOptions) Dim _syncAgent As SyncAgent = New SyncAgent() _syncAgent.LocalProvider = _sourceProvider _syncAgent.RemoteProvider = _destinationProvider _syncAgent.Direction = SyncDirection.UploadAndDownload _syncAgent.Synchronize() End Using End Using End Sub End Module
Sehr geehrter Herr Duggleby,
ich bin Abonnent des dot.Net Amgazins und habe mit Interesse den Artikel dot.net Magazin 5.08 Sync Framework Article and File Sync with VB.net gelesen.
Da ich jetzt auch über VS 2008 verfüge, wollte ich das Synchronisieren gleich mal ausprobieren.
Hierzu habe ich eine kurze Frage.
Ich will das Framework für die Synchronisation unsere SQL Server 2005 Webdatenbank mit unserer SQL Server 2005 Inhouse Datenbank verwenden.
Bis jetzt hat mir der Assistent immer eine .sdf Datei beim Client angelegt.
Geht die Synchronisation auch direkt zwischen zwei vollwertigen SQL Servern?
Ist das Framework dafür ausgelegt?
Brauch ich dann die .sdf überhaupt?
Wie kann ich das bewerkstelligen?
Gibt es ggf. bessere Alternativen als das Framework?
Ich will die Daten dabei auch bidirektional abgleichen.
Vielen Dank im voraus für ihre Antwort.
Mit freundlichen Grüßen
Rene Wack