Red Gate forums :: View topic - How to Trap Errors?
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
SQL Comparison SDK Previous Versions
SQL Comparison SDK Previous Versions forum

How to Trap Errors?

Search in SQL Comparison SDK Previous Versions forum
Post new topic   Reply to topic
Jump to:  
Author Message
CoastalData



Joined: 18 Jun 2009
Posts: 16

PostPosted: Sun Aug 09, 2009 6:50 pm    Post subject: How to Trap Errors? Reply with quote

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:
                    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
Back to top
View user's profile Send private message
Chris Auckland



Joined: 24 Oct 2006
Posts: 757
Location: Red Gate Software Ltd.

PostPosted: Tue Aug 11, 2009 10:31 am    Post subject: Reply with quote

Thanks for your post.

You can catch the SQL exception using:

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


I hope this helps.
_________________
Chris
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group