简体   繁体   中英

Linking to an SSRS report and setting parameters in the URL

I've got this block of code:

ErrorLogging.WriteLog(string.Format("Username = {0}, userkey = {1}, userID = {2}", CurrentUser.Username, CurrentUser.UserKey, CurrentUser.Username + CurrentUser.UserKey.ToString()));
ssrsRV.ProcessingMode = ProcessingMode.Remote;
ssrsRV.ServerReport.ReportServerUrl = new Uri(SystemConfig.SSRSServerURI);
ssrsRV.ServerReport.ReportPath = report.REPORT ?? string.Empty;
ssrsRV.ServerReport.SetParameters(new ReportParameter("UserID", CurrentUser.Username + CurrentUser.UserKey.ToString()));

The first line just proves to myself that I've got valid information in the those variables. The userID ends up being something like "jsmith162e4aa1-d8d3-427b-bd3d-71b7f0307856"

ssrsRV is an Microsoft.Reporting.WebForms.ReportViewer object.

When I try and run this code I get this error message:

The path of the item '/MyFolder/MyExampleReport.rdl~!@~!@' is not valid. The full path must be less than 260 characters long; other restrictions apply. If the report server is in native mode, the path must start with slash. (rsInvalidItemPath)

The exception is thrown by the SetParameters method, so I'm sure that's the problem, but I haven't tested not passing parameters at all.

Any clue what I'm doing wrong? What I should try next?

I'm dumb.

The code was perfect, the application was adding the "~!@~!@" to the report path in the database without displaying it to the user. If I write a SQL statement to remove those characters from the report path in the database, it works perfectly.

Thanks,

You'll need to declare the report parameter first:

ReportParameter[] RptParameters = new ReportParameter[1];

Then assign the parameter:

RptParameters[0] = new ReportParameter("UserID", CurrentUser.Username + CurrentUser.UserKey.ToString());

Then set the parameter:

ssrsRV.ServerReport.SetParameters(RptParameters);

See how this goes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM