使用 Detail 屬性來處理特定錯誤
為了進一步分類例外狀況,Reporting Services 會傳回 SOAP 例外狀況詳細數據屬性中子元素 InnerText 屬性中的其他錯誤資訊。 因為 Detail 屬性是一種 XmlNode 物件,所以您可以使用下列程式碼來存取 Message 子項目的內部文字。
如需包含在 Detail 屬性中所有可用的子項目清單,請參閱 Detail 屬性。 如需詳細資訊,請參閱 Microsoft .NET Framework SDK 文件中的<Detail 屬性>。
Try
' Code for accessing the report server
Catch ex As SoapException
' The exception is a SOAP exception, so use
' the Detail property's Message element.
Console.WriteLine(ex.Detail("Message").InnerXml)
End Try
try
{
// Code for accessing the report server
}
catch (SoapException ex)
{
// The exception is a SOAP exception, so use
// the Detail property's Message element.
Console.WriteLine(ex.Detail["Message"].InnerXml);
}
Try
' Code for accessing the report server
Catch ex As SoapException
If ex.Detail("ErrorCode").InnerXml = "rsInvalidItemName" Then
End If ' Perform an action based on the specific error code
End Try
try
{
// Code for accessing the report server
}
catch (SoapException ex)
{
if (ex.Detail["ErrorCode"].InnerXml == "rsInvalidItemName")
{
// Perform an action based on the specific error code
}
}
下列程式碼行會將在 SOAP 例外狀況中傳回的特定錯誤碼寫入主控台。 另外,您可以評估錯誤碼並執行特定的動作。
Console.WriteLine(ex.Detail("ErrorCode").InnerXml)
Console.WriteLine(ex.Detail["ErrorCode"].InnerXml);