| Author |
Message |
CoastalData
Joined: 18 Jun 2009 Posts: 16
|
Posted: Sun Aug 09, 2009 6:50 pm Post subject: How to Trap Errors? |
|
|
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 |
|
 |
Chris Auckland
Joined: 24 Oct 2006 Posts: 715 Location: Red Gate Software Ltd.
|
Posted: Tue Aug 11, 2009 10:31 am Post subject: |
|
|
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 |
|
 |
|
|
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