ReportExecutionService add datasource? - c#

Until now, I have been using ReportViewer.LocalReport to generate PDF outputs of locally embedded SSRS Reports, which use predefined datasources that get overridden in my C# application by run-time generated data...
// Set the DataSources
report.LocalReport.DataSources.Add(new ReportDataSource("MilkSolids", this.MilkSolidsTable));
report.LocalReport.DataSources.Add(new ReportDataSource("Ingredients", this.IngredientsTable));
The drawback of course, is that I have to use older versions of BIDS to design the report in. But now I have a new option of using a web reference from our SQL Server 2008 Report Server. This way, I could use BIDS 2008 to write my report in, and then make the report server do the rendering. This works like a charm for the pre-defined datasource; HOWEVER, I cannot find any information on how to override predefined datasources in the ReportExecutionService class.
Is this even possible?
If not, does anyone have another suggestion?

Related

Can a ReportViewer pull data by itself on local mode?

I was tasked with making a Webpage (aspx), which automaticly reads rdlcs, and generates a webpage, with the parameters at the top as webelements and the report as the main part of the page.
So far, I have tried reading the file as an XML-Doc, and just parsing the info out of there. But this may be done simpler. (I have no expirience with reports or rdl(c) files).
I have seen that there is a DataSets/DataSet/Query/CommandText-Tag, which can hold an SQL-Statement. Now this let's my boss and myself assume, that it is possible to make it already deliver this info by itself, which me coding this. On the other hand, I see nowhere any example for that.
My current code looks like this:
private string rdlcFilepath = "some/path/to/file.rdlc";
protected void Page_Load(object sender, EventArgs e) {
string sql = GetSqlStatementFromRdlcFile(rdlcFilepath);
DataTable dtTest = DatabseFacade.Execute_SQL(sql);
MainReportViewer.LocalReport.ReportPath = Server.MapPath(rdlcFilepath);
MainReportViewer.ProcessingMode = ProcessingMode.Local;
MainReportViewer.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dtTest));
MainReportViewer.LocalReport.Refresh();
}
So, I have 2 theories:
The CommandText-Tag tag is a ment for a "report server" and should be used only in ProcessingMode.Remote, and is not relevant when in Local mode.
I'm approaching this whole thing wrong.
If 2 is true, then probably the problem is manually adding the dtTest, and it should have some other instruction to make the report-element "pull" the data by itself.
My questions:
Is one of my assumptions correct, or what is going on?
Any other hints/links that may help?
I may note, that every tutorial/example I saw on the internet, that used ProcessingMode.Local, used an "external" datatable, and the LocalReport.DataSources.Add way.
Just for clearification, our (my boss' and my) ideal solution, would be some "magic" command, that makes the ReportViewer, use the information in the rdlc file, to connect to the database, and display the result. After all it contains all of the info, from connection-string to SQL-statement.
Please note that the rdl file is the Native SSRS report version, which is faster and easier to develop. The type of Project needed here is "Reporting Services Project", while the rdlc is the client side of the rdl file which is usually developed in normal visual studio web or desktop project, which is of course used as local report and usually takes more time to develop and you have to provide all DataSources, DataSets and Parametrs if there is any.
In my opinion, there is much simpler solution to your problem. You can actually setup remote or local SSRS reporting services server and this will enable you to work on the reports(rdl files) natively, which is basically cleaner and faster. In terms of performance too, I think that native mode scales out and outperform the local or client report option (.rdlc). Using this approach, you don't have to add DataSources or Datasets or Parametrs as all of this you will configure natively and use the configuration manager to configure Shared DataSources and Datasets. You will only have to authinticate the use in your page and provide the URI of your SSRS server, User name, password and report path.
To know more about configuring SSRS Server use this link please:
SQL Server Reporting Service Configuration Manager
there are also a lot of links online.
You can authinticate the user like the below code sample shows:
// Set the processing mode for the ReportViewer to Remote
ReportViewer1.ProcessingMode = ProcessingMode.Remote;
ServerReport serverReport = ReportViewer1.ServerReport;
ReportViewer1.ServerReport.ReportServerCredentials = new CustomReportCredentials("username", "password", "domain/Ip");
serverReport.ReportServerUrl =
new Uri("http://xx.xxx.xxx.222/ReportServer_MSSQLSERVER2016");
serverReport.ReportPath = "/Reports/Report3";
ReportViewer1.ServerReport.Refresh();
Here is a good link about Passing Credentials to Sql Report Server 2008
Passing Credentials to Sql Report Server 2008
That's all you need to do. just drag a report viewer and authenticate the user and that's it. hopefully this is helpful for you.

Crystal Report and Dataset

I am trying to add a crystal report into VS 2015, connected to a DataSet.
I managed to add the reportViewer to a form, create a DataSet with my SQL database, configured the report viewer using the wizard as to take the "clients" table from the DataSet (DataSet contains multiple tables), but when I run the application, I only get the column names and no data, whilst there are at least 20 clients in the database.
Am I missing something?
Have you created a connection to your datasource? If not you can do that via odbc.then in your designer see if you can load the data.before even running your app.

I want to run C# program without changing SQL Server instance or without changing SQL Server installed PC name

I have C# application which uses SQL Server R2 as its database. That database is on a separate PC by the name of SERVER. SQL Server's instance name also server.
My windows application uses DataSet to communicate with the database. Now my SQL installed PC name is change to another name, ex SERVERHP. Now all my coding works want to change my connection string. Are there any other easy way to do it ?
I am to tried to edit hosts file, but it does not work for me.
This is my coding style (http://goo.gl/FQrkp). I am using DataSet with DataAdapter with IDE designers.
I have 100 ~ 150 forms. Now I cannot compile all codings. I want to easy method to connect that SQL Server database.
I want to have a way to hide the change of the hostname of the computer
You have a couple of options:
Globally replace all server names with IP address in connection strings in the app
Globally replace all server names with the new server name in the app
Add a CNAME record to the DNS table on the server (assuming of course you're in the same network, which you are if you're using computer names)
Add an entry to the LMHOSTS file (you can add as many names as you'd like that point to the same IP)
As I understand, it is SqlConnection used to connect to database, or something like that. Why don't you use SqlConnectionStringBuilder? Then you can dinamically construct connection string you need. Also, to get list of servers, you can use SqlDataSourceEnumerator, from namespace System.Data.Sql.
It sounds like you want to have a way to hide the change of the hostname of the computer (Server/Desktop/Virtualized instance of Windows, whatever) that is running your SQL Server.
This isn't my area of expertise, but I can't think of a way to do it that only involves your application code and just the computer.
If you control the local DNS you can create a CNAME entry with the old name that "points" at the new one. Depending on how your connection strings are stored, you might have to edit them or you might not. But you won't have to worry about the location of your SQL Server changing again because you can always edit your CNAME to point at the new location.
Note for the future - not your current problem: If you continue to use MS SQL Server in particular you'll want to be careful about moving it to a computer where it isn't the default instance because then you need to put the instance name in the connection string as well, which might force you to edit all of your application web.configs and app.configs again.
Are you using Visual Studio 2012 with your development efforts? I ran into a conflict with the mini SQL db VS installs (Using Premium version) and had to modify the ConnectionStrings section of my Machine.config file to point to my SQL database. For whatever reason, VS will write references to the mini db in the Machine.Config file (for whatever version of .Net you are leveraging) throwing potetial conflicts.
The file can be found in %systemroot%\Microsoft.Net\Framework64\dot net version\Config
If you're using an x86 processor the Framework64 folder is just called 'Framework'.

Edit Crystal Report 8.5 file in .Net c#

I've got 2 applications:
1. App to prepare data for reporting - C# (.Net 1.1)
2. App to display report - C++ (maybe)
First app send parameters such a report file name, report parameters to second app via command line. Then second app display prepared report.
Now I want to change some report fields. My code in 1st app:
ReportDocument rDoc = new ReportDocument();
rDoc.Load(#"D:\reports\report_1.rpt");
rDoc.Database.Tables[0].Location = "newDBName.schema.oldTableName";
rDoc.SaveAs(#"D:\reports\report_1_modif.rpt",ReportFileFormat.VSNetFileFormat);
I want to modify rpt file because I want to take data from the archive database.
"CrystalDecisions.CrystalReports.Engine" reference version is 9.1.5000.0.
So 2nd app can't use modified rpt file because of incompatible versions. 2nd app can work only with 8.5 file formats.
When I open rpt file in CR Developer I can manually change location and save in 8.5 file format. In this case 2nd program normally works with modified file.
So my question is: "How can I in .Net C# open rpt file 8.5, modify and save in 8.5 format with another name?". Maybe I should use some unmanaged code?
Crystal Reports 8.5 was released in 2001. .Net in 2002.
I solved problem. My approach:
In C# code we update set of synonyms in DB after every user click "show report". After update each synonym still has the same name but follows to another table in different database.
We modified CR 8.5 file by hands: a) changed connection type to OLE DB (Native SQL Client) because of ODBC layer don't support synonyms b) set synonyms as tables locations instead of full table names.
Task solved!
UPD. We need p2soledb.dll to use OLE DB.

Load SSRS Report from file in C# in a service

We are looking into replacing Crystal with SSRS.
I would like to know if it is at all possible to load the .rdl or .rdl.data file in C# and generate the report to a memory stream.
I have seen some examples using the LocalReport, but this seems to be part of either the WinForms or WebForms assemblies.
So what I would like to know is:
Is it possible to load the report from file as part of our service.
Can we then generate the report to a Stream (lets say a memory
stream)
Can I do this without using the WebForms/WinForms assemblies in my
service
Can we achieve this without using the webservice for SSRS
I'm not sure that this is an answer, but lets call it supporting material.
I have this code example from msdn that shows how you can do this by creating a service client and calling a given report as a PDF and saves it to file stream.
http://msdn.microsoft.com/en-us/library/reportexecution2005.reportexecutionservice.render.aspx
The problem I'm currently having is finding the correct client object to interact with after pointing VS to the SSRS service. The object I'm using to interact with the service is:
ReportExecutionServiceSoapClient rs = new ReportExecutionServiceSoapClient();
However, the interface doesn't match my code example. So this is a little closer, but not an answer.
UPDATE: The correct Proxy class generator
Here's the link to how to generate the proxy correctly. You'll need the windows sdk installed (current is 7.1). You can find that on microsoft.com, like I did. Execute the command line and it'll generate a file for you. Include in project:
http://msdn.microsoft.com/en-us/library/ms155134%28v=SQL.110%29.aspx
UPDATE: Got the thing workin
I just had to generate the correct proxy. Ok, so for SSRS 2010, apparently they split report execution and management out into two services. The only one I needed to generate my report from a C# console app was the execution service. Maybe that's totally obvious to everyone but me :) ?
Ok so open up a Windows SDK command shell and put this stuff in it for the execution service:
wsdl /language:CS /n:"Microsoft.SqlServer.ReportExecution" http://<Server Name>/reportserver/reportexecution2010.asmx?wsdl /o:"ReportExecution.cs"
Go to C:\Program Files\Microsoft SDKs\Windows\v7.1 and pick up your ReportExecution.cs file. Copy and paste it in your project.
Then you just have to say this:
Microsoft.SqlServer.ReportExecution.ReportExecutionService rsExec =
new Microsoft.SqlServer.ReportExecution.ReportExecutionService();
rsExec.Credentials = System.Net.CredentialCache.DefaultCredentials;
rsExec.Url = #"http://<ServerName>/reportserver/ReportExecution2005.asmx";
Follow along the example from this link, which is the same one as above, and you should be generating some pretty awesome reports from your handy C# app.

Categories

Resources