asp.net report viewer error basics : operation not allowed - c#

I'm trying to get a handle on the basics of report viewer control in a ASP.net Webforms project with C#. I'm using Adventure Work reports to get a feel for the basics.
I have a report called SalesOrderNumber under Report Parts on my SQL server
I just want to be able to view it at this point
if (!Page.IsPostBack)
{
// Set the processing mode for the ReportViewer to Remote
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ServerReport serverReport = ReportViewer1.ServerReport;
// Set the report server URL and report path
serverReport.ReportServerUrl =
new Uri("(!removed!");
serverReport.ReportPath =
"/Report Parts/SalesOrderNumber";
// Create the sales order number report parameter
ReportParameter salesOrderNumber = new ReportParameter();
salesOrderNumber.Name = "SalesOrderNumber";
salesOrderNumber.Values.Add("SO50750");
// Set the report parameters for the report
ReportViewer1.ServerReport.SetParameters(
new ReportParameter[] { salesOrderNumber });
I get back
The operation you are attempting on item '/Report Parts/SalesOrderNumber' is not allowed for this item type. (rsWrongItemType)

Assign full path like
"http://ReportServername/ReportFolderName/reportname.rdlc"
Make sure Report servername, ServerPath , ReportMode ,rendermode also

I know it's an old question but still I found - it needs an answer.
As per my view, we should first check report path that we have set.
The SSRS ReportPath setting must specify the full report path.
So if you want to access a report, you should set the below path,
http://YourServerName//ReportServer?/Foldername/ReportName
Note: if you've not created a folder on report server then no need to write FolderName. Directly write ReportName.
I would prefer to see below link if you want to access report server using URL.
Click here
Hope it would be helpful to others who are facing the same issue.

Related

SSRS ServerReport Parameters lose pre-loaded value after internal postback

In our website, we are using the ReportViewer control to display SSRS reports. When the user clicks the link for a report, the code stuffs some initial variables to present the proper report, i.e.:
reportViewerNew.ServerReport.ReportServerUrl = new Uri(ReportURL);
reportViewerNew.ServerReport.ReportPath = ReportPath + ReportName;
Every Report has been created with at least one Parameter called "userName". On the report this is a hidden Report Parameter, and the value gets passed down into the Stored Procedure that populates the report so we can track who is requesting the information.
So, in the code we have a Switch block to load up an Array (the length depends on which Report is being called upon) that has at the very least this "userName":
default:
RptParameters = new ReportParameter[1];
RptParameters[0] = new ReportParameter("userName", UserID);
break;
With the array established, we then pass the pre-loaded values into the Report Parameters through the SetParameters method:
reportViewerNew.ServerReport.SetParameters(ReportParameters());
This all works great, and when the report runs I can check our database and see that the "userName" value has been passed down to our tracking.
However... this stops working if the report requires some interaction by the user to run the report -- for example choosing an option in one dropdown loads up a dependent dropdown, choosing a date that loads a dropdown with related choices, etc. It seems that this "internal postback" of the report is causing the Hidden Report Parameter "userName" to loose its value, and what then gets passed down is the account we use for the database connection.
I have placed a break-point in the code on the if (!Page.IsPostBack) line to catch the Report's "postback" but this is not being triggered... it seems to be internal to the ReportViewer control. I have tried looking up some kind of EventHandler for this postback in the documentation (https://learn.microsoft.com/en-us/dotnet/api/microsoft.reporting.webforms) but not seeing it.
Does anyone know why the Report Parameter would be losing its value, how to prevent it, or if I need to be handling this in a different way?
We are doing the exact same thing but using an Mvc.ViewUserControl wrapper to use the control in an MVC Project. Adding to the MVC project requires us to turn off Async rendering, but these steps may still work in your case, if not with a little tweaking.
We still set the parameters in the Page_Load method, so that the intial report call has the "userName" parameter set, but we also inject the parameter on every postback call like this:
Create a delegate method for the "SubmittingParameterValues" Report Viewer event:
private void ReportViewerNew_SubmittingParameterValues(object sender, ReportParametersEventArgs e)
{
ReportParameter userNameParam = e.Parameters.Where(rp => rp.Name.ToLower().Equals("username")).FirstOrDefault();
if (userNameParam != null)
{
userNameParam.Values.Clear();
userNameParam.Values.Add(UserID); // Assign your value here
}
}
Assign the delegate function to the report viewer in the Page_Init function. This will intercept the parameters every time before the report is sent to the server:
protected void Page_Init(object sender, EventArgs e)
{
reportViewerNew.SubmittingParameterValues += ReportViewerNew_SubmittingParameterValues;
}
That's it!

LocalReport hangs sometimes on render

When generating a RDLC report in a C#/WPF application, sometimes it hangs on render (call of render method doesn't return).
The report data comes from a C# object (which is filled in advance with data from a PostgreSQL database) so this issue is not SQL related.
I wonder:
How can I find out the reason?
Is there any way to enable the user to kill the report generation when it hangs?
Embedding the report generation in a using block (as seen in ReportViewer rendering hangs server after some executions) didn't solve the problem.
using (LocalReport report = new LocalReport())
{
report.ReportPath = #"C:\Path\To\MyReport.rdlc";
// Get the report data from db and fill it into MyReportData object.
MyReportData data = CreateReportData();
ReportDataSource headerDataSource = new ReportDataSource();
headerDataSource.Name = "HeaderDataSet";
headerDataSource.Value = data.Header;
report.DataSources.Add(headerDataSource);
// Add more data sources ...
// No report parameters are being used
report.Refresh();
pdfData = report.Render("PDF"); // here it hangs sometimes
}
As said above, the render-call hangs sometimes. After killing the application and generating exactly the same report again it works.

Crystal Report is not showing data after some time

i already went through the following questions.please don't mark as duplicate to my question. https://stackoverflow.com/questions/24432683/crystal-report-is-not-showing-data-after-some-time-in-cr-version-13-0-2000-0
I am facing this issue since last 1 month.My crystal report are working fine development environment (windows-7 32bit,VS2010,Crystal report V.13). I deployed on server (windows server-2012 64bit,core i5 ). Problem is that after some time report getting blank.I search a lot about that and use Dispose(),Close() method,right now I m using the following code.
public static void OpenPdfInBrowser(ReportClass RptReport)
{
string strFilename;
string strFolderName;
string strFile = String.Empty;
string strReportOutputName = String.Empty;
HttpResponse objResponse = HttpContext.Current.Response;
HttpSessionState objSession = HttpContext.Current.Session;
HttpServerUtility objServer = HttpContext.Current.Server;
strFolderName = objServer.MapPath("../ReportOutput");
if (Directory.Exists(strFolderName) == false)
{
Directory.CreateDirectory(strFolderName);
}
//Generate the File Name
strFilename = "";
strFile = objSession.SessionID.ToString() + "_" + DateTime.Now.Ticks.ToString() + ".pdf";
strFilename = strFolderName + "\\" + strFile;
//Set the File Name
DiskFileDestinationOptions diskOpts = new DiskFileDestinationOptions();
diskOpts.DiskFileName = strFilename;
//Set the Various Options
ExportOptions exportOpts = new ExportOptions();
exportOpts = RptReport.ExportOptions;
exportOpts.ExportDestinationType = ExportDestinationType.DiskFile;
exportOpts.ExportFormatType = ExportFormatType.PortableDocFormat;
exportOpts.DestinationOptions = diskOpts;
//Export the Report
RptReport.Export();
//Stream it to the Client
objResponse.ClearContent();
objResponse.ClearHeaders();
strReportOutputName = "Report";
objResponse.ContentType = "application/pdf";
objResponse.AddHeader("Content-Disposition", "inline;filename=Report.pdf");
objResponse.WriteFile(strFilename);
objResponse.Flush();
objResponse.Close();
//Delete the File
System.IO.File.Delete(strFilename);
//Close the Report Object
RptReport.Close();
RptReport.Dispose();
GC.Collect();
}
I am getting the following error in event viewer on deployment server.
The description for Event ID 4353 from source Crystal Reports cannot be found. Either the component that raises this event is not installed on your local computer or the installation is corrupted. You can install or repair the component on the local computer.
If the event originated on another computer, the display information had to be saved with the event.
The following information was included with the event:
The keycode assembly, BusinessObjects.Licensing.KeycodeDecoder.dll, cannot be loaded.
Any help will be greatly appreciated. thanks in adnvace.
Copy your asp.net folder to server virtual directory...
Not sure but hope ur problem will resolve. Best Luck.
The issues is looking like, related to the Crystal report installation on the server... If its working fine on the Development Machine and if All the applications required to run the crystal reports are installed on the Deployment server, then please, check.. Application Pool in IIS --> select the Application Pool used for the Web applicaiton --> Advanced Settings-> Enable 32-Applications --> Set this to "True" ..
Please, try and check...
After a long research my problem has been resolved by doing following changes in registry.Actually this issue is related to Print Job Limit which by default 75 I just extend its data size according to my requirement and it work for me.
Go to-->RUN----->Regedit
1-HKEY_LOCAL_MACHINE
2-SOFTWARE
3-SAP BUSINESS OBJECT
4-CRYSTAL REPORT FOR .NET FRAMEWORK(your version no.)
5-REPORT APPLICATION SERVER
6-SERVER
then got to "PrintJobLimit" PROPERTY and change its Data size to whatever you want.
thanks for every one who help me in this
Your approach is correct to use .close and . dispose but the best way to use it is :
Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload
cryRpt.Close()
cryRpt.Dispose()
End Sub
to open crystal report in PDF you can use http response it will be better in performance :
cryRpt = New ReportDocument
cryRpt.Load(Server.MapPath("Your report path"))
cryRpt.SetDataSource(Your data source)
cryRpt.ExportToHttpResponse(ExportFormatType.PortableDocFormat, Response, True, "ExportedReport")

SSRS Set "Credentials stored securely in the report server" programmatically

I am trying to set a given RDL report to use an embedded data source using my client application. I am using the ReportingService2005 class to interact with SSRS. I need to set the embedded data source to use "Credentials stored securely in the report server" and specify the username and password.
Thank you!
I solved the issue by first publishing the RDL, then calling into the ReportingService2005 GetItemDataSources() method. I then modified that datasource and subsequently called SetItemDataSources() to save the changes into SSRS. Below is a snippet of the code I accomplished this with:
var reportItem = report.TargetFolder + "/" + report.Name;
var dataSources = new DataSource[0];
dataSources = rs.GetItemDataSources(reportItem);
if (dataSources.Any())
{
var dataSource = (DataSourceDefinition)dataSources.First().Item;
dataSource.CredentialRetrieval = CredentialRetrievalEnum.Store;
dataSource.UserName = SsrsUsername;
dataSource.Password = SsrsPassword;
rs.SetItemDataSources(reportItem, dataSources);
}

Dynamically set Crystal Report still asks for db login

I am trying to deploy Crystal Reports in my MVC application. To get full use of the Crystal Report Viewer, I have to use a webform, which is working fairly well in my dev environment.
The application will be deployed on the user's servers and connect to their personal dbs. This means I do not have the final connection information when designing the report or the application.
I am able to successfully connect using their entries in the web.config file, load a DataTable with the report information, and pass it to the report. However, the report is still asking for the db credentials. The report is set to connect to my db, so it asks for my credentials and will not proceed without them. However, the final report shows the correct info from their db.
I am not sure if I need to change something in the report, or in the code behind. This is how I am setting the report ReportSource now:
protected void Page_Load(object sender, EventArgs e)
{
string strReportName = System.Web.HttpContext.Current.Session["ReportName"].ToString();
try
{
ReportDocument rd = new ReportDocument();
string strRptPath = Server.MapPath("~/") + "Rpts//" + strReportName;
rd.Load(strRptPath);
SqlParameter[] sqlParams = {};
DataTable testDt = DBHelper.GetTable("rptInvtDuplDesc", sqlParams);
rd.DataSourceConnections.Clear();
rd.SetDataSource(testDt);
CrystalReportViewer1.ReportSource = rd;
}
else
{
Response.Write("<H2>Nothing Found; No Report name found</H2>");
}
}
How do I prevent the report from asking for the original credentials?
EDIT:
If I pass the login to my db like this:
rd.SetDatabaseLogon("username", "password");
I do not get the db login again. The credentials have to be for the db used to create the report, but the displayed results are from the DataTable populated in the method above. If it has the data it needs from the current db, why does it need to connect to the original db?
EDIT2:
I have 2 data sources for this report. One is a table from the db and the other is the result from a stored procedure. I have now learned that is the cause of the extra login.
Have a look at my Blog post here on this.
There are a couple of actions required, but the main one is to create a new TableLogOnInfo instance, and then apply is using ApplyLogOnInfo.
You have to provide credentials for each datasouce in the report.
Ideally, the report will have a single datasource. If this is not possible, you need to provide credentials for each, or data for each.
Something like this works well if you want to provide the data:
rd.Database.Tables[0].SetDataSource(testDt);
rd.Database.Tables[1].SetDataSource(micssys);
Otherwise, something like this will allow the report to access the db directly for each datasource:
rd.SetDatabaseLogon("username","password}");

Categories