SQL Comparison SDK
Latest version: 10.0
Knowledge Base
Using SQL Data Compare mappings in projects using the API
Category: SDK, API & Command line
Date: 03 Feb 2011
Product: SQL Comparison SDK
Versions: 6,7
A powerful feature of SQL Data Compare is the ability to use the object mappings set in a saved SQL Data Compare project file programmatically.
Line 65 shows the method ReplayUserActions, which allows the mappings to be accessed from the project file.
- [VB]
- 1 Imports RedGate.SQL.Shared
- 2 Imports RedGate.SQLCompare.Engine
- 3 Imports RedGate.SQLDataCompare.Engine
- 4 Imports RedGate.SQLDataCompare.Engine.ResultsStore
- 5
- 6
- 7 Module Test
- 8 Sub test()
- 9 Dim e As New SyncNow( "D:\TLHORT\Misc Files\SF- Sync.sdc")
- 10 e.Synchronize()
- 11 End Sub
- 12 End Module
- 13
- 14 Public Class SyncNow
- 15 Dim pathToProjectFile As String
- 16
- 17 Dim project As RedGate.SQLDataCompare.Engine.Project
- 18 Dim db1, db2 As Database
- 19 Dim mappings As SchemaMappings
- 20 Dim session As ComparisonSession
- 21 Dim livedb As LiveDatabaseSource
- 22
- 23 Dim provider As SqlProvider
- 24 Dim block As ExecutionBlock
- 25
- 26 Dim executor As BlockExecutor
- 27 Public Sub New( ByVal PhysicalPathToProjectFile As String)
- 28 Me.pathToProjectFile = PhysicalPathToProjectFile
- 29
- 30
- 31 End Sub
- 32
- 33 Public Sub Synchronize()
- 34 Try
- 35 Compare()
- 36 GetScript()
- 37 ExecuteScript()
- 38 Catch ex As Exception
- 39 Throw
- 40 Finally
- 41 session.Dispose()
- 42 block.Dispose()
- 43 End Try
- 44 End Sub
- 45
- 46 Private Sub Compare()
- 47 project = project.LoadFromDisk(pathToProjectFile)
- 48
- 49 Dim db1 As New Database
- 50 Dim db2 As New Database
- 51
- 52 livedb = DirectCast(project.DataSource1, LiveDatabaseSource)
- 53 db1.RegisterForDataCompare(livedb.ToConnectionProperties(), Options.Default)
- 54
- 55
- 56 livedb = DirectCast(project.DataSource2, LiveDatabaseSource)
- 57 db2.RegisterForDataCompare (livedb.ToConnectionProperties(), Options.Default)
- 58
- 59
- 60 mappings = New SchemaMappings
- 61 mappings.Options = project.Options
- 62
- 63 'The table mappings are NOT imported from the project file :(
- 64 mappings.CreateMappings(db1, db2)
- 65 project.ReplayUserActions(mappings)
- 66 session = New ComparisonSession
- 67 session.Options = project.Options
- 68 session.CompareDatabases(db1, db2, mappings)
- 69 End Sub
- 70
- 71 Private Sub GetScript()
- 72 provider = New SqlProvider
- 73 block = provider.GetMigrationSQL(session, True)
- 74 End Sub
- 75
- 76 Private Sub ExecuteScript()
- 77 executor = New BlockExecutor
- 78 executor.ExecuteBlock(block, livedb.ServerName, livedb.DatabaseName, livedb.IntegratedSecurity , livedb.UserName, livedb.Password)
- 79
- 80 End Sub
- 81
- 82 End Class
- [/VB]
Document ID: KB200712000211 Keywords: SQL,Data,Compare,API,mapping,replayuseractions
Was this article helpful?
SQL Comparison SDK
- Licenses.licx is not a valid Win32 application
- Application licensing invalidated by renaming assembly
- Excluding a table from a data comparison
- Manually licensing Red Gate assemblies
- RedGate.Licensing.Helper.dll is attempting managed execution inside OS Loader lock
- Troubleshooting SQL Comparison SDK licensing
- SQL Compare synchronization error 'Full-Text Search is not installed'
- Using SQL Data Compare mappings in projects using the API
- Licensing automated builds with NAnt
- Licensing ASP .NET applications
- Running SQL code inside SQL Comparison SDK applications
- Creating an HTML report of schema differences in C#
- Creating a synchronization script without batch markers
- Creating an HTML report of schema differences in Visual Basic .NET
- SQL Toolkit has become SQL Comparison SDK
- SQL Comparison SDK column mapping
- Executing your own SQL queries together with SDK synchronization
- Error 1603 occurring during installation
- Licensing SDK applications in Visual Studio 2010
all SQL products
- Compatibility of Red Gate tools in 64-bit environments
- Application has encountered an error and needs to close
- Error message after installing SQL Toolbelt - The description for Event ID ( 1 ) in Source ( nview_info ) cannot be found.
- Changing the temporary directory used by the installer
- Toolbelt Installer "hanging" while "scanning volumes"
- Login failing with "trusted SQL Server connection" error when using RunAs
all products
- Some Red Gate products identified as containing a trojan by Anti-Virus software
- Activation may fail with Unknown Error -1
- Product uses web help although a CHM file is available locally
- Argument exception resulting from missing environment variable
- Check for updates may fail when used through proxies
- 'Unidentified Publisher' error when repairing or uninstalling
- Licensing activates product as standard edition
- Moving Red Gate software products to another machine
- Red Gate tools log locations
- The application UI opening slowly when there is no internet access
SQL Comparison SDK
all SQL products
all products
- Red Gate product acknowledgements
- Activating your products
- Activating your products
- Red Gate bundle history
- Check for updates
- Troubleshooting Check for Updates errors
- Current versions
- Deactivating your products
- Installing Red Gate products from the .msi file
- Requesting additional activations
- Serial numbers for bundles
- Reactivating using a different serial number
- Extending your trial
- Finding your serial numbers
- Moving a serial number from one computer to another
- No response received for manual activation
- Licensing and activation resources
- Licensing and activation resources
- Troubleshooting licensing and activation errors
- Licensing and activation FAQs
- Red Gate tools log file locations
- Download old versions of products
- Download product prerequisites & utilities
- Support & upgrades
- Upgrading your software
- Upgrading FAQs

Licensing and distribution