Friday, March 9, 2012

ex.Message in debug mode is much shorter

Exception ex.Message I am getting in debug mode calling AcquireConnection is much shorter than the logged message in run time because all the errors come to output window in debug. Is there any way to get all these errors description from exception object in debug time to be able to parse it?

Thanks.

What you are saying does not make sense. The exception details will always bee the same debug or otherwise. The exception will only have one message, but you suggest there should be more. You could check the InnerException property of the caught exception, that may give something. I really do not understand how you are describing the two modes, with all errors or otherwise.

Is this perhaps to do with a UI? If so try the IErrorCollectionService interface. This allows you to get details of the fire error, warning methods called from the IDTSComponentMetaData90.

|||

Thanks for your reply and sorry for not making this question clear.
Will try to explain what actually I am actually looking for.

Below the simplified piece of my code in script task
Try
connection = connMgr.AcquireConnection(Nothing)
Catch ex As Exception
'Dts.Events.FireError(1, ex.TargetSite.ToString, ex.Message, "", 0)
MsgBox(ex.Message)
Dts.TaskResult = Dts.Results.Failure
End Try

Deliberately providing wrong psw for the connection and running the package in debug (F5)
In the msgbox reading the message "Exception from HRESULT: 0xC0202009".

Running the same package in "Start Without Debugging" (ctrl+F5), getting the more informative msgbox:


Error: 0xC0202009 at EnvConfig, Connection manager "DB_SOURCE": An OLE DB error has occurred. Error code: 0x80040E4D.
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E4D Description: "Communication link failure".
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E4D Description: "TCP Provider: An existing connection was forcibly closed by the remote host.
".
An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E4D Description: "Login failed for user 'DTSUSE'.".

The message looks like as a collection that what I am actually looking for to get access to. I need to extract only latest description like "Login failed for user 'DTSUSE'" and log it.

Thanks, Vadim.

|||

Ok, now I see. This is not a SSIS issue, rather a .Net programming issue, in so much as it is actually bad practice to just catch the general Exception type. It is also very common, we all do it! Really you should catch targeted exceptions as they are richer classes that have more information relevant to the exception thrown.

If you catch the SqlException type you can get access to the Errors collection, that is a property on the SqlException class. That will give you that extra level of detail, both for the messages and things like the source.

No comments:

Post a Comment