Passing Parameter to SSRSfrom asp.net - asp.net

I need to pass a parameter to reporting services which is on the reporting services server on my computer from my asp.net. The parameter is SellerID
MyReportViewer.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Remote
MyReportViewer.ServerReport.ReportServerUrl = New Uri("http://jean-daniel/ReportServer_SQLEXPRESSADDD")
' Report Server URL
MyReportViewer.ServerReport.ReportPath = "/Report Project2/Auction History"
' Report Name
MyReportViewer.ShowParameterPrompts = False
MyReportViewer.ShowToolBar = False
MyReportViewer.ServerReport.Refresh()
Dim params(0) As ReportParameter
params(0) = New ReportParameter("SellerID", "201", False)
MyReportViewer.ServerReport.SetParameters(params)
MyReportViewer.ServerReport.Refresh()
Any idea on how to do this?

To pass parameters to a report via code you have to do it like this:
C#:
ReportParameter[] params = new ReportParameter[1];
params[0] = new ReportParameter("SellerId", ParameterValue , false);
MyReportViewer.ServerReport.SetParameters(params);
MyReportViewer.ServerReport.Refresh();
VB.NET:
Dim params(0) As ReportParameter
params(0) = New ReportParameter("SellerId", "YourValue", false)
MyReportViewer.ServerReport.SetParameters(params);
MyReportViewer.ServerReport.Refresh();
Here you can find a complete example Generate SQL Server Reporting Services (SSRS) Report as PDF from URL with VB.NET or C#.NET

Related

How to view Crystal Report without CrystalReportViewer?

I have a web application where I just need to view my report embedded in a web page. I don't want CrystalReportViewer side controls like printing, zooming, paging etc. Its look and feel should be like a scanned document picture. Any help?
Yes this is possible. Here's a code snippet that converts the crystal report object (in memory stream) to Pdf, Word, or Excel.
using CrystalDecisions.Web;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
ReportDocument rpt = new ReportDocument();
string path2 = path + reportName;
rpt.Load(path2);
CrystalDecisions.CrystalReports.Engine.Database crDatabase = rpt.Database;
ConnectionInfo crConnectionInfo = new ConnectionInfo();
crConnectionInfo.ServerName = server;
crConnectionInfo.DatabaseName = db;
crConnectionInfo.UserID = crystalUser;
crConnectionInfo.Password = pwd;
crConnectionInfo.IntegratedSecurity = false;
<<<<<<report logic here>>>>>>>>>>>
CrystalDecisions.Shared.ExportFormatType typ = CrystalDecisions.Shared.ExportFormatType.PortableDocFormat;
if (exportFormatType == "doc")
typ = CrystalDecisions.Shared.ExportFormatType.WordForWindows;
if (exportFormatType == "xls")
typ = CrystalDecisions.Shared.ExportFormatType.Excel;
MemoryStream ms = (MemoryStream)rpt.ExportToStream(typ);

How to execute an SSRS .rss script file in IIS/ASP.NET

I need to execute a .rss SSRS script file within an ASP.NET application running in IIS 7.x. How can I do that?
Do I have to configure the IIS AppPool that is running my web application to have elevated privileges such that I can start up the rs.exe console application passing the .rss script to it the way I would otherwise execute an .rss script file outside of IIS?
Or is there another way? Does Visual Studio/.NET provide any mechanism for bootstrapping an .rss script file without needing the rs.exe console application? Is my only option to make the rs.exe console application available to my web application running in IIS?
So, I figured it out. If you're wondering how to create a History Snapshot of a report on your SSRS Reports Server using the ReportServices2010 proxy, here's one example and one way you can accomplish it (many thanks to kyzen for sharing his insight in directing me to the SOAP API):
Dim basicHttpBinding As New BasicHttpBinding()
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm
basicHttpBinding.SendTimeout = New TimeSpan(0, 10, 0)
Dim endPoint As New EndpointAddress("http://server/reportserver/ReportService2010.asmx")
Dim instance As New ReportingService2010SoapClient(basicHttpBinding, endPoint)
Dim itemPath As String = "/Path/to/report"
Dim warnings() As Warning
Dim historyId As String = Nothing
Dim values As ParameterValue() = Nothing
Dim credentials As DataSourceCredentials() = Nothing
Dim t As New TrustedUserHeader()
instance.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation
instance.ClientCredentials.Windows.ClientCredential = New Net.NetworkCredential("userid", "password", "domain")
instance.Open()
oServerInfoHeader = instance.CreateItemHistorySnapshot(t, itemPath, historyId, warnings)
and in C#:
BasicHttpBinding basicHttpBinding = new BasicHttpBinding();
basicHttpBinding.Security.Mode = BasicHttpSecurityMode.TransportCredentialOnly
basicHttpBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.Ntlm
basicHttpBinding.SendTimeout = New TimeSpan(0, 10, 0)
EndpointAddress endPoint = new EndpointAddress("http://server/reportserver/ReportService2010.asmx");
ReportingService2010SoapClient instance = new ReportingService2010SoapClient(basicHttpBinding, endPoint);
string itemPath = "/Path/to/report"
Warning warnings[];
string historyId;
ParameterValue values[];
DataSourceCredentials credentials[];
TrustedUserHeader t = new TrustedUserHeader();
instance.ClientCredentials.Windows.AllowedImpersonationLevel = System.Security.Principal.TokenImpersonationLevel.Impersonation;
instance.ClientCredentials.Windows.ClientCredential = New Net.NetworkCredential("userid", "password", "domain");
instance.Open();
oServerInfoHeader = instance.CreateItemHistorySnapshot(t, itemPath, historyId, warnings);

Crystal Report in VS2008 doesn't display data on web

I have a problem with my crystal reports in Visual Studio 2008, and after searching and searching I got nothing.
My file CrystalReportxxx.rpt has an xsd file as dataschema. A datatable is created and it's passed to report as datasource. To fill the datatable, my application connects to Oracle database.
For showing rows or data with CrystalReportViewer, the report needs credentials like logid and password of database. However, if I export this report to a PDF file, then no credentials are needed and PDF file shows all rows.
This is my code:
Dim dt As DataTable
FunctionsOP.CreaDataTable("pkg_list.sp_list", True, ospEntry,
dt)
Dim oRpt As New Reportes.CrystalReportxxx
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
oRpt.SetDataSource(dt)
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
I suppose that when setting:
oRpt.SetDatabaseLogon("userxxx", "passwordxxx")
and report shows no data, is because credentials are wrong.
My question is: How to bypass this credential input?
Is it mandatory to input userid, password, etc for using a xsd file in my Crystal
Report?
What is strange to me is that when I export that report to PDF, there is no
problem. Data is shown OK and no credential is needed:
Dim exportOpts As ExportOptions = oRpt.ExportOptions
oRpt.ExportOptions.ExportFormatType =
ExportFormatType.PortableDocFormat
oRpt.ExportOptions.ExportDestinationType =
ExportDestinationType.DiskFile
oRpt.ExportOptions.DestinationOptions = New
DiskFileDestinationOptions
CType(oRpt.ExportOptions.DestinationOptions,
DiskFileDestinationOptions).DiskFileName = Server.MapPath("../Temp/" +
PDFName)
oRpt.Export()
oRpt.Close()
oRpt.Dispose()
I also tried this code:
Dim dt1 As New DataTable : Dim dt2 As New DataTable
Dim oRpt As New Reportes.CR_IndicadorA11
Dim ParRep As ReportClass = oRpt
SetConnectionsReports(ParRep)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_sum", True, Nothing, dt1)
FunctionsOP.CreaDataTable("pkg_Listar_Tipos.sp_indicador_a11_det", True, Nothing, dt2)
oRpt.SetDataSource(dt1)
oRpt.OpenSubreport("CR_sub_indicadorA11_det.rpt").SetDataSource(dt2)
CrystalReportViewer1.Visible = True
CrystalReportViewer1.EnableDatabaseLogonPrompt = False
CrystalReportViewer1.ReportSource = oRpt
CrystalReportViewer1.DataBind()
CrystalReportViewer1.Dispose()
Public Sub SetConnectionsReports(ByRef Rpt As ReportClass)
Dim server, base, user, pass As String
server = "SRVBDDESA2.DOMINTERN0XXX.LOCAL" ' also with IP number is the same
base = "DESAOPINT"
user = "ORGPOL"
pass = "desarrollo"
For Each connection As IConnectionInfo In Rpt.DataSourceConnections
connection.SetConnection(server, base, user, pass)
Next
End Sub

Crystal Report Credentials Prompt after deployment

I am Publishing crystal reports on remote server using the following code. when i try to run the crystal report page Crystal report viewer prompt me for database info. As the published crystal report were created using development server. In my crystal report i was using OLEDB ADO Connection
MyRepository _MyRepository = new MyRepository();
System.Data.SqlClient.SqlConnection myConnection = new System.Data.SqlClient.SqlConnection();
myConnection.ConnectionString = ConfigurationManager.ConnectionStrings["MyConnStr"].ConnectionString;
System.Data.SqlClient.SqlCommand MyCommand = new System.Data.SqlClient.SqlCommand("dbo.spMySP");
MyCommand.Connection = myConnection;
MyCommand.Parameters.Add("#PositionID", SqlDbType.Int).Value = (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue));
MyCommand.CommandType = System.Data.CommandType.StoredProcedure;
System.Data.SqlClient.SqlDataAdapter MyDA = new System.Data.SqlClient.SqlDataAdapter();
MyDA.SelectCommand = MyCommand;
ASale _DS = new ASale();
MyDA.Fill(_DS, "dbo.spMySP");
rptSale oRpt = new rptSale();
oRpt.SetDatabaseLogon("sa", "mypass");
oRpt.SetDataSource(_DS);
oRpt.SetParameterValue(0, "param1");
oRpt.SetParameterValue(1, "param2");
oRpt.SetParameterValue(2, "param3" );
oRpt.SetParameterValue(3, (cmbPositions.SelectedValue == "" ? 0 : Convert.ToInt32(cmbPositions.SelectedValue)));
CrystalReportViewer1.ReportSource = oRpt;
HI,
When you develop your report, do you use Windows authentication to login to the database to build the report?
Maybe you can try to open the report again and try to update your database set up on the crystal report. E.g. by using the same login information your use on your code.
What I normally do is to put the database server name and the database name on to the code as well
E.G.
_CReportDoc.SetDatabaseLogon(username, pw, ServerName, DB)
Not sure if it could help

How to pass parameters to SSRS report programmatically

I'm looking for a little help on programmatically passing parameters to a SSRS report via VB.NET and ASP.NET. This seems like it should be a relatively simple thing to do, but I haven't had much luck finding help on this.
Does anyone have any suggestions on where to go to get help with this, or perhaps even some sample code?
Thanks.
You can do the following,: (it works both on local reports as in Full Blown SSRS reports. but in full mode, use the appropriate class, the parameter part remains the same)
LocalReport myReport = new LocalReport();
myReport.ReportPath = Server.MapPath("~/Path/To/Report.rdlc");
ReportParameter myParam = new ReportParameter("ParamName", "ParamValue");
myReport.SetParameters(new ReportParameter[] { myParam });
// more code here to render report
If the Report server is directly accessible, you can pass parameters in the Querystring if you are accessing the repoort with a URL:
http://MyServer/ReportServer/?MyReport&rs:Command=Render&Param1=54321&Param2=product
You can add output formatting by adding the following on the end of the URL:
&rs:Format=Excel
or
&rs:Format=PDF
It's been a while since I did this code, but it may help:
Your web project has to be a Web Site, and not a project of type "ASP.Net Web Application", or you won't be able to add the reference mentioned below.
Right click on the project and add an ASP.Net folder - App_WebReferences. You'll have to specify the server where your SRS is; choose the .asmx.
Once it's added, the folder under that level is called RSService, and under that are 2 things: reportservice.discomap & .wsdl.
In my VB, I do Imports RSService and Imports System.Web.Services.Protocols, then...
Dim MyRS As New ReportingService
The reporting service is on a different server than the webserver the app is on, so I can't do the following: MyRS.Credentials = System.Net.CredentialCache.DefaultCredentials
Instead: MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3),
where the rs1/2/3 are the login to SRS box, password to SRS box, & domain name". (These are encrypted in my web.config.)
Then, a mass-paste:
MyRS.Credentials = New System.Net.NetworkCredential(rs1, rs2, rs3)
Dim ReportByteArray As Byte() = Nothing
Dim ReportPath As String = "/SRSSiteSubFolder/ReportNameWithoutRDLExtension"
Dim ReportFormat As String = "PDF"
Dim HistoryID As String = Nothing
Dim DevInfo As String = "<DeviceInfo><Toolbar>False</Toolbar></DeviceInfo>"
'Dim x As ReportParameter - not necessary
Dim ReportParams(0) As ParameterValue
ReportParams(0) = New ParameterValue()
ReportParams(0).Name = "TheParamName"
ReportParams(0).Value = WhateverValue
Dim Credentials As DataSourceCredentials() = Nothing
Dim ShowHideToggle As String = Nothing
Dim Encoding As String
Dim MimeType As String
Dim ReportHistoryParameters As ParameterValue() = Nothing
Dim Warnings As Warning() = Nothing
Dim StreamIDs As String() = Nothing
'Dim sh As New SessionHeader() - not necessary
''MyRS.SessionHeaderValue = sh - not necessary
ReportByteArray = MyRS.Render(ReportPath, ReportFormat, HistoryID, DevInfo, ReportParams, Credentials, _
ShowHideToggle, Encoding, MimeType, ReportHistoryParameters, Warnings, StreamIDs)
'(Yay! That line was giving "HTTP error 401 - Unauthorized", until I set the credentials
' as above, as explained by http://www.odetocode.com/Articles/216.aspx.)
'Write the contents of the report to a PDF file:
Dim fs As FileStream = File.Create(FullReportPath, ReportByteArray.Length)
fs.Write(ReportByteArray, 0, ReportByteArray.Length)
fs.Close()
Call EmailTheReport(FullReportPath)
If IO.File.Exists(FullReportPath) Then
IO.File.Delete(FullReportPath)
End If
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.Reset();
Label1.Visible = false;
ReportViewer1.Visible = true;
DataSet dataSet = new DataSet();
dataSet = new ClassBLL().Load_Report_Detail(TextBox1.Text,
ddlType.SelectedValue, levelcode, fields);
ReportDataSource datasource = new ReportDataSource("DataSet_StoreprocedureName",
dataSet.Tables[0]);
if (dataSet.Tables[0].Rows.Count == 0)
{
ReportViewer1.Visible = false;
}
ReportViewer1.LocalReport.ReportPath = Server.MapPath("") + #"\Report.rdlc";
ReportViewer1.LocalReport.DataSources.Clear();
ReportViewer1.LocalReport.DataSources.Add(datasource);
string fields="name,girish,Z0117";
string[] filedName = fields.Split(',');
ReportParameter[] param = new ReportParameter[2];
//for (int i = 0; i < filedName.Length; i++)
//{
param[0] = new ReportParameter(filedName[0], filedName[0], true);
param[1] = new ReportParameter(filedName[3], filedName[3], true);
// }
ReportViewer1.LocalReport.SetParameters(param);
ReportViewer1.ServerReport.Refresh();

Resources