Report viewer can't access reports in other database server - c#

I have a web application in asp.net 3.5 published in apps server.I have few SSRS reports deployed in a database server which needed to be accessed from the web app.Both the server are in same network.I am using a report viewer control to show the reports and i am passing the report path dynamically.I am also sending the login credentials from code behind.
The problem is that the report is identified correctly and the proper report parameter are also shown.But when i click the view report button no data appears.I have Sql server 2008 r2 and report viewer version 9.0
Please help me with this. here is a code snippet...
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
ReportViewer1.ShowCredentialPrompts = false;
IReportServerCredentials irsc =
new CustomReportCredentials("user", "pass", "domain");
ReportViewer1.ServerReport.ReportServerCredentials = irsc;
ReportViewer1.ServerReport.ReportServerUrl =
new Uri("http://72.0.170.205:80/ReportServer");
ReportViewer1.ShowParameterPrompts = true;
ReportViewer1.ShowPrintButton = true;
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ReportViewer1.ServerReport.Refresh();
ReportViewer1.ServerReport.ReportPath = Request.QueryString["val"];
}
}

Did you check that the reports run ok with the same credentials on http://72.0.170.205:80/Reports ?
Don't know if this can be of any help but here are the differences I see in my implementation :
I don't call ReportViewer1.ServerReport.Refresh();
I call this.RegisterRequiresViewStateEncryption(); ( Had to disable it sometimes )
my reportDisplay application is not the root app. Because of conflicts, back in SSRS2005 I had to use a different name for its session cookie in the web.config. Kept it since then
<sessionState cookieless="UseCookies" cookieName="ASP.NET_SessionId.myCustomName"/>

Protected Sub Load_Report()
Dim Connection As New SqlConnection(Connection_String) 'Server Connection String
Dim Data_Table As New DataTable("DataTable1") *'Create New Data Table in DataSet having same columns as are there in your Datatable*
Dim Query As String
Query = "SELECT Caption,Mobile,Age,City FROM Bond.Book"
Dim Command As New SqlCommand(Query, Connection)
Dim Table_Adapter As New SqlDataAdapter(Command)
Table_Adapter.Fill(Data_Table)
ReportViewer1.ProcessingMode = ProcessingMode.Local
ReportViewer1.LocalReport.ReportPath = Server.MapPath("Book.rdlc")
ReportViewer1.LocalReport.DataSources.Clear()
ReportViewer1.LocalReport.DataSources.Add(New ReportDataSource("Book_DataSet", Data_Table))
ReportViewer1.LocalReport.Refresh()
End Sub
This worked for me. I am able to load report viewer on server and view server data

Related

Error while loading SSRS Report from SSRS Server

In my mvc project reports are deployed on separate SSRS server and we are loading the SSRS Reports with help of iframe, problem with this is its asking for user name and password while accessing the reports with iframes. To remove the user id ans password prompt I was trying to implement the solution provided on this link
and I changed the code in ReportTemplate.aspx.cs file as below to send the credentials referring this link:
rvSiteMapping.Width = 800;
rvSiteMapping.Height = 600;
rvSiteMapping.ProcessingMode = ProcessingMode.Remote;
IReportServerCredentials irsc = new CustomReportCredentials(#"userid", "password", #"\");
rvSiteMapping.ServerReport.ReportServerCredentials = irsc;
rvSiteMapping.ShowCredentialPrompts = true;
rvSiteMapping.ServerReport.ReportServerUrl = new Uri("http://12.25.2.24/Reports");
rvSiteMapping.ServerReport.ReportPath = "/report/AssetDetail";
rvSiteMapping.ServerReport.Refresh();
I am getting below error:
The underlying connection was closed: An unexpected error occurred on a send.
Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host.
An existing connection was forcibly closed by the remote host
However its working perfectly fine with below code:
rvSiteMapping.Width = 800;
rvSiteMapping.Height = 600;
rvSiteMapping.ProcessingMode = ProcessingMode.Local;
ReportsDataSet ds = new ReportsDataSet();
var connectionString = ConfigurationManager.ConnectionStrings["LowryATS_Tenant2ConnectionString"].ConnectionString;
SqlConnection conx = new SqlConnection(connectionString);
SqlDataAdapter adp = new SqlDataAdapter("SELECT * FROM Assets", conx);
adp.Fill(ds, ds.Assets.TableName);
rvSiteMapping.LocalReport.ReportPath = Request.MapPath(Request.ApplicationPath) + #"AssetReport.rdlc";
rvSiteMapping.LocalReport.DataSources.Add(new ReportDataSource("ReportsDataSet", ds.Tables[0]));
Can anybody please help me with this problem. We are using ssrs 2016 on ssrs server.

SQL report with subreport not showing on page

I have created a SQL report using Visual Studio (also works when using Report Builder). The report consists of the main report with sub reports in it. When running the report via Visual Studio or Report Builder or publishing to the Report Server, it works fine and the main report and sub reports show correctly.
I have an ASP.Net MVC application which displays the report but it also allows the user to specify a where clause before running it. When the report is run via the MVC application, it shows only the main report and then says:
The subreport 'sub' could not be found at the specified location
[MVC application direcotry] Please verify that the subreport has been
published and that the name is correct.
even though the report is there.
The following is a snippet of the code which loads and displays the report:
if (ReportFileName != null && ReportFileName != "")
{
ViewBag.Title = "Reporting";
reportViewer.ProcessingMode = ProcessingMode.Local;
reportViewer.SizeToReportContent = true;
reportViewer.Width = Unit.Percentage(100);
reportViewer.BackColor = System.Drawing.Color.White;
reportViewer.Height = Unit.Percentage(100);
SqlConnection conx = new SqlConnection(ConfigurationManager.ConnectionStrings[""].ConnectionString);
SqlDataAdapter adp = new SqlDataAdapter(Basequery, conx);
DataTable dt = new DataTable();
adp.Fill(dt);
adp.Fill(ds.Tables[0]);
reportViewer.LocalReport.ReportPath = ReportFileName;
}
reportViewer.LocalReport.DataSources.Clear();
reportViewer.LocalReport.DataSources.Add(new ReportDataSource("ReportDataSet", ds.Tables[0]));
reportViewer.LocalReport.Refresh();
ViewBag.ReportViewer = reportViewer;
return PartialView("ReportView");
is there something that im missing?

How do I connect Crystal reports to multiple database?

I have a webpage which has a drop-down. In the drop-down there is a list of databases from a server. On selecting the drop-down document numbers are shown and we can click and generate crystal report.
My problem is I have given data-source for one database in the crystal report. Suppose I select other databases. How can I connect to the report for multiple databases?
Any inputs will be greatly appreciated.
Are you using CR designer or Visual Studio to make your reports? Because there is a connection section in the field explorer window. Generally, it is not recommend to connect to multiple DB. Even if you are using for example 2 or more stored procedures for your report, you can complicate your life if they don't have a common key.
The below is what we use, it should work for you. Basically you have to make sure that for every table the report accesses (or command, or view, etc.), the connection is set. I'm not aware of a way to set it only on the main report.
// create a ReportDocument
using (ReportDocument reportDoc = new ReportDocument())
{
reportDoc.Load(path); // path to your .rpt file
// get the connection string you want to use
SqlConnectionStringBuilder conInfo = new SqlConnectionStringBuilder("<your connection string>");
Tables crTables = reportDoc.Database.Tables;
int tablecounter = 0;
foreach (CrystalDecisions.CrystalReports.Engine.Table crTable in crTables)
{
CrystalDecisions.Shared.TableLogOnInfo logonInfo = crTable.LogOnInfo;
logonInfo.ConnectionInfo = new ConnectionInfo()
{
DatabaseName = conInfo.InitialCatalog,
ServerName = conInfo.DataSource
};
if (conInfo.IntegratedSecurity)
{
logonInfo.ConnectionInfo.IntegratedSecurity = true;
}
else
{
logonInfo.ConnectionInfo.UserID = conInfo.UserID;
logonInfo.ConnectionInfo.Password = conInfo.Password;
}
crTable.ApplyLogOnInfo(logonInfo);
}
}

Failed to retrieve data from the database. Details: [Database Vendor Code: 1370 ] in Crystal Reports using ASP.ET

I have goggled alot but did't find any solution.
I am using Visual studio 2012 with My Sql as Database and Crystal reports.
I have deployed web application on WINDOWS SERVER 2008 and when i access from remote it give me following error message, as given in following screen.
i am using the following code
string databaseName = "hr";
string serverName = "192.168.137.6";
string userID = "userID";
string pass = "xxxxxxxxxxx";
protected void btn_search_Click(object sender, EventArgs e)
{
CrystalReportViewer1.Visible = true;
ReportDocument reportDocument = new ReportDocument();
string reportPath = Server.MapPath(#"~/GeneralEmpReports/test.rpt");
reportDocument.Load(reportPath);
reportDocument.SetParameterValue("D", tbx_ddoCode.Text.ToUpper());
reportDocument.SetDatabaseLogon(userID, pass, serverName, databaseName);
CrystalReportViewer1.ReportSource = reportDocument;
}
Here i want to add that only Stored Procedures gives me the above error, if i made a report from Tables then no error and execute perfectly. I have checked stored procedure through Navicat tool (GUI Administrative tool for mysql) , it works fine.
I have added the following connection on server through control Panel==>Administrative tools ==>Data Source (ODBC) as shown in following figure.
After searching a lot, i came to know that i am doing mistake in Server Name,
Server Name should be DSN name not IP address. Create System DSN name on your production server same as given in development computer as in following.
Data source Name : DSN_Name
TCP/IP Server : In development PC give it blank it means localhost but in development Server give IP address.
User: UserName
Paswword: Password
Database: Database Name
Following is the code which works fine.
string databaseName = "hr";
string serverName = "hr_domain"; // DSN Name
string userID = "xxxxxxx";
string pass = "xxxxxxxx";
protected void btn_search_Click(object sender, EventArgs e)
{
CrystalReportViewer1.Visible = true;
ReportDocument reportDocument = new ReportDocument();
string reportPath = Server.MapPath(#"~/GeneralEmpReports/test.rpt");
reportDocument.Load(reportPath);
reportDocument.SetDatabaseLogon(userID, pass, serverName, databaseName);
reportDocument.SetParameterValue("D", tbx_ddoCode.Text.ToUpper());
CrystalReportViewer1.ReportSource = reportDocument;
}

Database login prompt when clicked on subreports

I have a report and when clicked on link subreport i get Database login form.I have given all the necessary connection strings but still it asks for login info.sub reports opens in my local system but when installed in Client system i get this problem. what am i missing or what should i do ?
I have found that when setting the database connection in code for a crystal report you need to set the connection on every single table in the report Database Definition. You can do this like:
private static void SetConnectionInfo(ReportClass report, string ReportServer, string ReportDatabase)
{
TableLogOnInfo tInfo = new TableLogOnInfo();
ConnectionInfo connectionInfo = tInfo.ConnectionInfo;
connectionInfo.IntegratedSecurity = true;
connectionInfo.ServerName = ReportServer;
connectionInfo.DatabaseName = ReportDatabase;
foreach (Table t in report.Database.Tables)
{
t.ApplyLogOnInfo(tInfo);
}
foreach (ReportClass subReport in report.Subreports)
{
SetConnectionInfo(subReport, ReportServer, ReportDatabase);
}
}

Categories