Processing Messages

EHSUserEHSUser Posts: 9
edited September 21, 2006 1:48PM in SQL Toolkit Previous Versions
I wrote a small program using your SQL Compare 5 Toolkit to compare and sync 2 databases.
The code snippets in the documentation don't completely apply to me because I am writing the error messages to a file, not directly to the console.

I tested the program on a few of our sites and it seemed to work fine.

I have one site in particular where the register method fails, but for some reason I am not getting any error messages either. The text file that is generated is completely blank.

I followed the example code as closely as I could, and replaced it with code that would work for this application.

The program is just supposed to take a snapshot of the database, save it to a file, and print any error messages to a txt.

Private Sub btn_SaveSnapshot_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_SnapShot.Click
        Dim db1 As New RedGate.SQLCompare.Engine.Database()
        Try
            btn_SnapShot.Enabled = False
            db1.Status = New StatusEventHandler(AddressOf Me.StatusCallback)
            If chk_OWindowsAuth.Checked = False Then
                db1.Register(New ConnectionProperties(servername, databasename, username, password), myOptions)
            Else
                db1.Register(New ConnectionProperties(servername, databasename), myOptions)
            End If
            db1.SaveToDisk(snapShotFilename)
            objWriter.Close()
            MessageBox.Show("The snapshot operation has completed successfully.", "Snapshot Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
        Catch
            MessageBox.Show("The snapshot operation has completed with Errors.", "Snapshot Failure", MessageBoxButtons.OK, MessageBoxIcon.Error)
        Finally
            db1.Dispose()
            Start(snapShotPath & "EHSSnapshotLog.txt")
            btn_SnapShot.Enabled = True
        End Try
    End Sub

    Sub StatusCallback(ByVal sender As Object, ByVal e As StatusEventArgs)
        If Not (e.Message Is Nothing) Then
            objWriter.WriteLine(e.Message)
        End If

        If e.Percentage <> -1 Then
            ProgressBar1.Value = e.Percentage()
            ProgressBar2.Value = e.Percentage()
        End If

    End Sub



This seems to work fine if the register method completes successfully, but
if it fails I get no output at all.

I'm not sure if I am going about this the right way or not.
Thanks,
Kevin
EHS

Comments

  • Brian DonahueBrian Donahue Posts: 6,590 New member
    Hello Kevin,

    In order to troubleshoot the register method, you need to use a try/catch block to write the exception message to the console so you can diagnose and fix the problem, for instance:
    Try
    db1.Register(New ConnectionProperties(servername, databasename), myOptions)
    Catch e As System.Data.SqlClient.SqlException
    Console.WriteLine(e.Message)
    End Try
    
    The error message should reveal the real cause of the registration failure, ie, invalid password, etc.
Sign In or Register to comment.