Skip to content

Latest commit

 

History

History
68 lines (59 loc) · 3.66 KB

File metadata and controls

68 lines (59 loc) · 3.66 KB
title description author ms.author ms.date ms.service ms.subservice ms.topic ms.custom helpviewer_keywords
Prevent invalid requests
Learn how to prevent invalid requests by analyzing your application flow and ensuring that the requests being sent to the report server are valid.
maggiesMSFT
maggies
09/25/2024
reporting-services
report-server-web-service
reference
updatefrequency5
invalid requests [Reporting Services]
exceptions [Reporting Services], invalid requests
valid requests [Reporting Services]

Prevent invalid requests

You can prevent some types of exceptions from being thrown by analyzing your application flow and ensuring that the requests being sent to the report server are valid. For example, you might have applications that enable users to add or update the name of a report, data source, or other report server item. If that's the case, you should validate the text that a user might enter. You should always check for reserved characters before sending the request to a report server. Use conditional if statements or other logical constructs in your code to alert the user that they haven't met the conditions necessary to send requests to the report server.

In the following, simplified C# example, users are presented with a friendly error message when they attempt to create a report with a name that contains a forward slash (/) character.

// C#  
private void PublishReport()  
{  
   int index;  
   string reservedChar;  
   string message;  
  
   // Check the text value of the name text box for "/",  
   // a reserved character  
   index = nameTextBox.Text.IndexOf(@"/");  
  
   if ( index != -1) // The text contains the character  
   {  
      reservedChar = nameTextBox.Text.Substring(index, 1);  
      // Build a user-friendly error message  
      message = "The name of the report cannot contain the reserved character " +  
         "\"" + reservedChar + "\". " +  
         "Please enter a valid name for the report. " +  
         "For more information about reserved characters, " +  
         "see the help documentation";  
  
      MessageBox.Show(message, "Invalid Input Error");  
   }  
   else // Publish the report  
   {  
      Byte[] definition = null;  
      Warning[] warnings = {};  
      string name = nameTextBox.Text;  
  
      FileStream stream = File.OpenRead("MyReport.rdl");  
      definition = new Byte[stream.Length];  
      stream.Read(definition, 0, (int) stream.Length);  
      stream.Close();  
      // Create report with user-defined name  
      rs.CreateCatalogItem("Report", name, "/Samples", false, definition, null, out warnings);  
      MessageBox.Show("Report: {0} created successfully", name);  
   }  
}  

For more information about the types of errors that can be prevented before requests are sent to the report server, see SoapException Errors table. For more information about further enhancing the previous example using try/catch blocks, see Use try and catch blocks.

Related content