Only Console Apps Supported?

jbsoundjbsound Posts: 35
edited July 17, 2006 3:49PM in SQL Toolkit Previous Versions
It seems that if I want to reference RedGate.SQLCompare.Engine.Database with anything other than a console application in .NET it won't work.

I have added the required references to the .NET (VB WinForms App) project, added the licenses information, added the 'Imports ...' statements, but can't seem to have VS.NET find the RedGate.SQLCompare.Engine.Database reference.

Is the Toolkit only for console applications?

Any help is appreciated!

Thanks,

JB

Comments

  • Hi there,
    Should be no problem.
    I took the SQLCompare code snippit installed by default in
    %Program Files%Red Gate\SQL Bundle 5\Toolkit Sample Files\Automating SQL Compare\VB
    changed the app over to a "Windows Application" using Visual Studio 2003. Modified the SynchronizeDatabases method to look like
    Sub SynchronizeDatabases(ByVal writer As System.IO.TextWriter)
    
            Dim db1 As Database = New Database
            Dim db2 As Database = New Database
            
    
            db1.Register(New ConnectionProperties(".", "WidgetDev"), Options.Default)
            db2.Register(New ConnectionProperties(".", "WidgetLive"), 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
    
    
    
            writer.WriteLine("Messages:")
    
            Dim message As Message
    
            For Each message In work.Messages
                writer.WriteLine(message.Text)
            Next
    
            writer.WriteLine("Warnings:")
    
            For Each message In work.Warnings
                writer.WriteLine(message.Text)
            Next
    
    
            'print out the SQL used to synchronize
    
            Dim block As ExecutionBlock = work.ExecutionBlock
    
            writer.WriteLine("SQL to synchronize:")
    
            writer.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()
    
        End Sub
    
    (Nb. I changed the databases because they did not exist on my current SQL Box.)
    Added a form, made this form the main form of the app, added a label and a button to the form and added the code below behind the button
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            Dim sb As System.IO.StringWriter = New System.IO.StringWriter
    
            SynchronizeDatabases(sb)
            Label1.Text = sb.ToString()
    
        End Sub
    
    The Windows form mini-app ran fine, clicked the button and all worked as expected. Can you send more information about the error message please?
    Regards
    David
  • I appreciate it, David.

    I've done exactly the same as you have, porting the console application sample to a Windows forms application.

    The problem is that Visual Studio doesn't seem to resolve the 'Database' class and reports an error that it could not be found.

    As I said, I am referencing the DLLs and included the Imports statement at the top.

    So, the issue is to find out what's different between your code and my code.

    JB
  • Hi JB,
    Either you like you could email me your source or could you try what I did and take the example code snippit shipped with SQL Bundle 5 and turn it into a Windows App?
    my email address is
    david.connell@red-gate.com
    Regards
    David
  • Alright, I found the problem, which was user error:

    Instead of using the RedGate.SQLCompare.Engine reference, I used the RedGate.SQLDataCompare.Engine reference. Obviously a big difference.

    Once the proper reference was used, my problem went away. :)

    Thanks for your time and help!

    JB
Sign In or Register to comment.