How to Trap Errors?

Automate and integrate using the SQL comparison API

How to Trap Errors?

Postby CoastalData » Sun Aug 09, 2009 5: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()
                        If executeSql Then
                            fnWriteLine("Updating target database")
                            executor.ExecuteBlock(block, "", "DB_147089_ktgpdata", False, "DB_147089_ktgpdata_user", "Bulld0g")
                            fnWriteLine("Skipping: Updating target database")
                        End If

                        fnWriteLine("The database was NOT updated! See Error Below!")
                        fnWriteLine("Error #:(" & Err.Number & ")" & vbCrLf & "Description: " & Err.Description)
                        fnWriteLine("'GetLast500Errors' Returns this: " & executor.GetLast500Errors.ToString)
                        '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
Posts: 16
Joined: Thu Jun 18, 2009 8:03 pm

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

Thanks for your post.

You can catch the SQL exception using:

Code: Select all
Catch e As SqlException

I hope this helps.
Chris Auckland
Posts: 760
Joined: Tue Oct 24, 2006 1: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