How to Trap Errors?

Automate and integrate using the SQL comparison API

Moderator: Chris Auckland

How to Trap Errors?

Postby CoastalData » Sun Aug 09, 2009 6:50 pm

Hello, I've tried several different methods to try and catch the error message generated by sql data compare via the API in VB.Net, and have had no luck at all.

Check out the "catch" below; any suggestions for how better to extract the actual error message? What I've been having to do is to save the sql source to file, and then load that file into Enterprise Manager, and then execute it there to see what's wrong.

Code: Select all
                    Dim executeSql As Boolean = True
                    Dim executor As New BlockExecutor()
                    Try
                        If executeSql Then
                            fnWriteLine("Updating target database")
                            executor.ExecuteBlock(block, "mssql04.discountasp.net", "DB_147089_ktgpdata", False, "DB_147089_ktgpdata_user", "Bulld0g")
                        Else
                            fnWriteLine("Skipping: Updating target database")
                        End If

                    Catch
                        fnWriteLine("The database was NOT updated! See Error Below!")
                        fnWriteLine("Error #:(" & Err.Number & ")" & vbCrLf & "Description: " & Err.Description)
                        fnWriteLine("'GetLast500Errors' Returns this: " & executor.GetLast500Errors.ToString)
                    Finally
                        'Always dispose the SqlProvider's  ExecutionBlock because GetMigrationSQL could throw an exception but still set it
                        block = provider.Block
                        If (TypeOf block Is ExecutionBlock) Then
                            block.Dispose()            'dispose of the objects to delete temporary files   
                        End If
                    End Try
CoastalData
 
Posts: 16
Joined: Thu Jun 18, 2009 9:03 pm

Postby Chris Auckland » Tue Aug 11, 2009 10:31 am

Thanks for your post.

You can catch the SQL exception using:

Code: Select all
Catch e As SqlException
      Console.WriteLine(e.Message)


I hope this helps.
Chris
Chris Auckland
 
Posts: 757
Joined: Tue Oct 24, 2006 2:12 pm
Location: Red Gate Software Ltd.


Return to SQL Comparison SDK Previous Versions

Who is online

Users browsing this forum: No registered users and 0 guests