See Also

Work Members  | RedGate.SQLCompare.Engine Namespace

Requirements

Namespace: RedGate.SQLCompare.Engine

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: RedGate.SQLCompare.Engine (in RedGate.SQLCompare.Engine.dll)

Language

Visual Basic

C#

C++

C++/CLI

Show All

See Also Requirements Languages RedGate.SQLCompare.Engine Send comments on this topic.

Work Class

RedGate.SQLCompare.Engine Namespace : Work Class

Used to calculate the work to be done to synchronize databases.

For a list of all members of this type, see Work members.

Object Model





Inheritance Hierarchy

System.Object
   RedGate.SQLCompare.Engine.Work

Syntax

[Visual Basic]
Public NotInheritable Class Work    Implements ICancellable 
[C#]
public sealed class Work : ICancellable 
[C++]
public __gc __sealed class Work : public ICancellable 
[C++/CLI]
public ref class Work sealed : public ICancellable 

Remarks

The Work class is used to convert a set of Differences into an ExecutionBlock containing SQL script, which can be used to synchronize two databases. It also provides Warnings and Messages about the work to be done.

ScriptObject can be used to generate scripts for individual database objects.

Note that you should not re-use a Work object; you should re-create a new object every time.

Example

This example shows how to compare and synchronize two databases.

[C#] 

Database db1=new Database(); 
Database db2=new Database(); 
  
db1.Register(new ConnectionProperties(".", "WidgetStaging"), Options.Default); 
db2.Register(new ConnectionProperties(".", "WidgetProduction"), Options.Default); 
  
Differences differences=db1.CompareWith(db2, Options.Default); 
  
foreach (Difference difference in differences) 

    //make sure the difference is selected so it is included in the synchronization 
    difference.Selected=true; 

  
Work work=new Work(); 
  
//calculate the work to do using sensible default options 
//the script is to be run on WidgetProduction so the runOnTwo parameter is true 
work.BuildFromDifferences(differences, Options.Default, true); 
  
//we can now access the messages and warnings 
  
Console.WriteLine("Messages:"); 
  
foreach (Message message in work.Messages) 

    Console.WriteLine(message.Text); 

  
Console.WriteLine("Warnings:"); 
  
foreach (Message message in work.Warnings) 

    Console.WriteLine(message.Text); 

  
//print out the SQL used to synchronize 
  
ExecutionBlock block=work.ExecutionBlock; 
  
Console.WriteLine("SQL to synchronize:"); 
  
Console.WriteLine(block.GetString()); 
  
//and run the SQL 
  
RedGate.SQL.Shared.BlockExecutor executor=new RedGate.SQL.Shared.BlockExecutor(); 
executor.ExecuteBlock(block, ".", "WidgetProduction"); 
  
//dispose of the objects 
block.Dispose(); 
db1.Dispose(); 
db2.Dispose(); 
    

[Visual Basic] 

Dim db1 As Database = New Database()
Dim db2 As Database = New Database()


db1.Register(New ConnectionProperties(".", "WidgetStaging"), Options.Default)
db2.Register(New ConnectionProperties(".", "WidgetProduction"), Options.Default)

Dim differences As Differences = db1.CompareWith(db2, Options.Default)

Dim difference As Difference

For Each difference In differences
    'make sure the difference is selected so it is included in the synchronization
    difference.Selected = True
Next

Dim work As Work = New Work()

'calculate the work to do using sensible default options
'the script is to be run on WidgetProduction so the runOnTwo parameter is true

work.BuildFromDifferences(differences, Options.Default, True)

'we can now access the messages and warnings

Console.WriteLine("Messages:")

Dim message As Message

For Each message In work.Messages
    Console.WriteLine(message.Text)
Next

Console.WriteLine("Warnings:")

For Each message In work.Warnings
    Console.WriteLine(message.Text)
Next


'print out the SQL used to synchronize

Dim block As ExecutionBlock = work.ExecutionBlock

Console.WriteLine("SQL to synchronize:")

Console.WriteLine(block.GetString())

'and run the SQL

Dim executor As BlockExecutor = New BlockExecutor

executor.ExecuteBlock(block, ".", "WidgetProduction")

'dispose of the objects
block.Dispose()
db1.Dispose()
db2.Dispose()

Requirements

Namespace: RedGate.SQLCompare.Engine

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

Assembly: RedGate.SQLCompare.Engine (in RedGate.SQLCompare.Engine.dll)

See Also

Work Members  | RedGate.SQLCompare.Engine Namespace

 

 


© 2003 - 2007 Red Gate Software Ltd. All Rights Reserved.