Report viewer in wpf and selection formula - wpf

I have a WPF application that I would like to present SQL Server Reporting Services sql 2008 reports in. I understand we have to use host widow control and then in report viewer control. I want to use remote processing mode.
My code sample is :
I have added namespaces:
using System.Windows.Forms;
using System.Windows.Forms.Integration;
using Microsoft.Reporting;
using Microsoft.ReportingServices;
using Microsoft.Reporting.WinForms;
My XAML:
xmlns:wfi="clr-namespace:System.Windows.Forms.Integration;assembly=WindowsFormsIntegration"
xmlns:wf="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms"
xmlns:wfr="clr-namespace:Microsoft.Reporting.WinForms;assembly=Microsoft.ReportViewer.WinForms"
Title="ReportHost" Height="300" Width="300">
<Grid>
<wfi:WindowsFormsHost Height="100" Margin="39,27,39,0" Name="winFormsHost" VerticalAlignment="Top" >
<wfr:ReportViewer x:Name="rptViewer" ProcessingMode="Remote" />
</wfi:WindowsFormsHost>
</Grid>
Code:
rptViewer.ServerReport.ReportServerUrl =
new Uri("http://mymachine-:8080/ReportServer_myreports");
rptViewer.ServerReport.ReportPath="/Reports/mytestreport.rdl";
rptViewer.ServerReport.Refresh();
My question is that how how can I set selection formula in microsoft report viewer control [like crystal report]. Or miscroft provided any this else which behave like selection formula in crystal reports.
And when I run the code it show only report viewer in host window control but not the report data in window.
Please some one provide me all step list, Which I have to fallow to get required result with sample code.
Quick response will be appricated.

For the path to the report, leave off the .rdl extension:
rptViewer.ServerReport.ReportPath="/Reports/mytestreport";
Sorry, I'm not familiar with Crystal Reports's selection formulas.

Using ReportViewer in remote mode is painful in several ways, one of which is that you have to code everything as parameters - you can't just set the selection formula and be done with it.
I recommend you switch to using LocalReport. All you have to do is retrieve the RDL from the server, execute the queries, and set the DataSources property. The main advantage is you really don't need the server at all and you don't need to worry about server configuration changes breaking your application, but you also get better performance (usually) and much more flexibility.
If you are using LocalReport, you can embed your reports in your .exe or .dll using ReportEmbeddedResource, or you can have them as files alongside the .exe or .dll and use ReportPath, or you can have them on the server and download them to the temp directory for use.
When using LocalReport it is trivial to do arbitrary selection: Just add some LINQ. In other words, replace this:
viewer.LocalReport.DataSources.Add(
new ReportDataSource("Sales", GetSalesData()));
with this:
viewer.LocalReport.DataSources.Add(
new ReportDataSource("Sales", GetSalesData().Where(d => d.Amount > 10)));
The only reasons I can think of where you might be required to run the reports on the server and deal with the pain and inefficiency are: 1. If the client can't get to the data any other way due to security lockdown, and 2. If a huge data set is retrieved and processed down to a small set and the client is small or remote. In either of these cases your only option is to manually add parameters to the RDL and then use those parameters to filter your data.

thanks Ray Burns,
According to our discussion I concluded that:
1) If I used remote processing mode then I have to pass all the parameter on which I have to filter the record.
2) If I used local processing mode then In C# code I have to set data source of the report.
But
As I am using microsoft Reporting services sql 2008. I have designed the reports in SQL server Business intellegence Studio and their I have written queries / or calling stored procedure and also set the data source their. So its means that repoorts should contain only design and all data base related things will be handle in C# code?
And all the client machine have the reports locally, is that good way?

Related

Universal Windows Platform (UWP) and SQL Server

I've hit a wall when it comes to how the Universal Windows Platform connects/manages/interacts with a local SQL Server database. My current project (WPF using .NET Framework 4.8) that I'm interested in porting over to UWP uses EntityFramework 6 with ADO.NET models and it works like a charm. No issues at all. UWP on the other hand, well I'll just say that I have absolutely no idea what's going on when it comes to connecting to a local instance of SQL Server. I've gone through about 3-4 different guides/templates and none have worked. I really want to use UWP and take advantage of all the new features coming for Windows 10 v2004, but it doesn't look like this will happen.
As I currently understand the process, I need to essentially create two separate projects within the same solution. One is the UWP main program and the other would be a .NET Core class library that targets the .NET Standard 2.0 platform. I also have read that EntityFramework 6 is not supported on .NET Core or UWP, so the only way is by using EntityFrameworkCore (more specifically NuGet package Microsoft.EntityFrameworkCore.SqlServer). So I installed it on the .NET Core class library and then set a reference from the UWP app to the class library. Because the local SQL Server is already up and running, I'm not doing what is called the 'code first' approach to the creation of all the models/DbContext.cs files. Based on what I've read, the ONLY way to import a currently existing SQL Server into the data model is by use of the Scaffold-DbContext command with a standard connection string through the package manager. Surprisingly, this worked on the first attempt and the models and DbContext were all created without any issues.
This is about as far as I seem to be able to get as everything after does nothing but throw exceptions. If I try to pass any C# code using the DbContext to retrieve any data from the database, I get about 10-15 exceptions that essentially say the program can't find or connect to the database. I have manually edited the connection string in every way imaginable, but nothing seems to work. I also tried to manually set up a new connection using Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient.SqlConnectionStringBuilder and System.Data.SqlClient.SqlConnection but they all fail with the same exceptions.
Sorry for the long post but at this point, I really don't know what's going on and would really appreciate any feedback you all could offer.
Update 1
So, I went back through my currently working app on .NET Framework and looked for the connection string in the App.config file to see what the regular EntityFramework is using and it's completely different than anything I've used before. My guess is that it's generating a completely custom connection string that includes references to all sorts of files and a property called 'ProviderName'. Will try cutting and pasting this string into UWP to see if it'll work.
Update 2
I think I'm missing something fundamental on this. I can generate the scaffold with a connection string without any issues, but if I attempt to open a connection at runtime using the same connection string, I'm getting errors.
Finally was able to get a connection at runtime after months of trial and error. Without getting into too much detail, here's what worked for me (assuming EFCore has already generated a DbContext file):
Enable Enterprise Authentication.
Enable TCP/IP connections to the SQL Server instance.
In Visual Studio's server explorer, click Add Connection. If you already have a connection saved for the database, right click the server and click Modify Connection
In the connection properties window, click the Advanced button. Make a note of all of the listed parameters and their values and save it.
Open the data context file that isn't able to connect and add a using statement for Microsoft.Data.SqlClient. Now locate the OnConfiguring method. Use a SqlConnectionStringBuilder and configure all of the parameters from the advanced connection properties that were saved earlier.
And that should work. If there are still errors, I would double check the parameters to make sure they were all entered correctly.
Hope this post will help out anyone else dealing with this issue.

SSIS: Flat File default length

I have to import about 50 different types of files every day. Some of them with a few columns, some inculde up to 250 columns.
The Flat File connection always defaults all columns to 50 chars.
Some columns can be way longer than 50 chars, and will of course end up in errors.
Currently i am doing a stupid search&replace with notepad++ - Opening all SISS packages, replacing:
DTS:MaximumWidth="50"
by
DTS:MaximumWidth="500"
This is an annoying workaround.
Is there any possibility to set a default length for flatfile string columns to a certain value?
I am developing in Microsoft Visual Studio Professional 2015 and SQL Server Data Tools 14.0.61021.0
Thanks!
I don't think that there is a way to achieve this from SQL Server Data Tools.
But you can do some workaround to achieve this:
Easiest solution, In the Flat file connection manager - Advanced Tab, select all columns (using Ctrl key) and change the data length property for them all in one edit. (detailed in #MikeHoney answer)
You can use BIML (Business Intelligence Markup Language) to create ssis package, if you're new to BIML you can access to BIML Script website for detailed tutorials.
You can create a Small application that loop over .dtsx files in a folder and replace DTS:MaximumWidth="50" with DTS:MaximumWidth="500" using normal String.Replace function or using Regular expressions. (you can read my answer # Automate Version number Retrieval from .Dtsx files to see an exmaple on reading .dtsx file using Regular expressions)
Function To Read and Replace content of dtsx file (Vb.Net)
Public Sub FixDTSX(byval strFile as string)
dim strContent as string = string.empty
Using sr as new Io.StreamReader(strFile)
strContent = sr.ReadToEnd()
sr.Close()
End Using
strContent = strContent.Replace("DTS:MaximumWidth=""50""","DTS:MaximumWidth=""500""")
Using sw as new Io.StreamWriter(strFile,False)
sw.Write(strContent)
sw.Close()
End Using
End Sub
There is a way to achieve what you want using the standard Visual Studio SSDT UI, although it is quite obscure. AFAIK it works in every version of this editor since SQL Server 2005.
With the package open, from the Connection Managers pane, right-click your Flat File Connection and choose Edit. Then navigate to the Advanced page. Then multi-select the columns you want to change (e.g. shift-click a range or ctrl-click a specific set). Now the Properties appearing at the right will be applied to all the selected columns.
In the example shown below, I have set all the selected columns to a width of 255.
Esteban,
I suggest you use the Object Model API which allows you to develop SSIS packages programmatically. Using that, you can make use of any .net code that allows you to gather data/metadata from text files. Also, the assumption is that, since you are using SSIS, you already might be familiar with writing code in C#/VB.Net
Now, if you are just starting with the Object Model API, there would be a huge learning curve (but it is worth learning it if SSIS is your day to day life). If you do not have the time to invest right now, I would recommend you to use a library I wrote (called Pegasus) which greatly simplifies how you can use the Object Model API; you can create your packages in an almost declarative fashion (using C#).
On Github, there is an example that shows how to create a package that loads any number of text files with differing schemas in a given folder. See here; specifically the method GenerateProjectToLoadTextFilesToSqlServerDatabase().
In the example, I use a third party .Net library called lumenworks.framework to probe delimited files and get their metadata. Using this library, I get the names of the columns; and I also infer data types and lengths based on sampling the first 'n' number of rows. (In my code, I am only inferring ints, dates and strings; if you have more data types, add relevant code accordingly). Or you can specify one specific data type and length (looks like you want to use string of 500 chars) for all your columns. [Or (in some cases), you might have this metadata available outside in a excel file/config file.] Then I use this metadata to configure my text file connection managers programmatically.
YOu can download the code from Github and run the DataFlowExample by specifying where your source files are and see how far it gets you.
Another recommendation would be Biml, but I am not sure if you can incorporate your own/third party full fledged C# code (not just snippets) into Biml workflow. If you can, then go with Biml.
Let me know if you have any questions.

How to create an RDL using the report class generated from the RDL schema

I have a project where we are creating a custom report generator for SSRS 2008R2. This project allows the user to select fields from a database and then create and store the RDL on the report server.
For some of the initial proof of concept attempts we have been using XMLText writer to generate the XML file. While this works this seems to be very cumbersome and I don't have a lot of confidence in how the schema is being generated as being 100% bulletproof. A second attempt is actually using the generated class from the RDL as my object model. Where I am stuck here is there is almost zero documentation on how to use this object. MSDN has a tutorial on updating the model but it very basic in concept.
I'm looking for some guidance on the preferred approach.
1) continue with the XML generation
2) use the RDL object to create the reports
3) I have also considered using the SSRS endpoint where a dummy report is created and stored on the server then using the RDL object model to update the report with the necessary fields, groups etc.
I haven't tested the third option but it seems as this would minimize the amount of coding for the creation of the document.
Thanks for any suggestions or ideas
I just built a program that creates an SSRS report from a report template and a stored procedure.
I am using the RDLObjectModel to create the report. And RDLSerializer to allow saving the report to a file or the report server. I first load a report template from our report server through the SSRS web service to deserialize the server report into and RDLObjectModel. I then derive parameters for the report fields, and derive fields from the stored procedure to make a report dataset.
The problem that I ran into is that I wasn't able to serialize the report object to be able to save it to the server or to a file because in RDL2008 RDLSerializer is private. Then I came across an article that saved me a lot of headaches. http://ucodia.fr/2011/10/advanced-reporting-services-part2-rdl-serializer/
This is a much better approach that using XMLTextWriter. This should provide you enough to get things rolling.
I ran into the same problem where I was using RdlObjectModel to create my report object but I was unable to serialize it. There is a way to overcome that issue where you can still get instance of the RdlSerializer and call serialize method using reflection
You can find the implementation at the following link

How to do a mailing using a reporting tool?

Env.: Reporting Services or XTraReport, SqlServer Express 2008 R2, VS2008, WinForms, C#
Hi All,
My WinForms app must send a customized letter to a bunch of people (whose contact info is in SqlServer). This is the typical job for Word Mail/Merge.
But I'd like to do it without Word installed on client computers. I'd rather use MS Reporting Services (or DevExpress XtraReport).
The problem is those tools allow me to put text boxes for name and address (that's fine) but they aren't real word processors. I need to embed custom fields in the flow of the text. This is easily done in Word but I can't find a way to do it in Reporting Services.
Note: I'm a newbie as far as reporting is concerned.
Please help,
TIA.
Serge.
In MS Reporting Services, you can set the value of a text field to a VB expression, rather than a fixed string. Use that expression to insert your database fields into the text.
For example you might have an expression like this one:
="Dear "+Fields!FirstName.Value+","
For a more sophisticated approach, you could use placeholders in your text and replace them with some regular expressions. In that case you'd probably want to embed the code in the report or an assembly and just call it as a function from your text field.
I discovered that DevExpress XtraReport can do what I want: One can embed fields into the text of RichEdit controls:
Hello [firstName], your subscription elapsed on [lastDay!dd/MM/yyyy]
Also, the mailing issue is solved by having a report which only consists in a Detail band.
I would have preferred a MS Reporting Services solution but this one nicely fits my needs.

Sql Server reporting services 2008 Rendering Excel

I am trying to produce SSRS reports to integrate with a MOSS Dashboard. Reporting Services 2005 only seems to be able to render .xls out of the box. Does SSRS 2008 have the ability to render in xlsx format?
To the best of my experience, exporting to excel2007 is not built into SSRS2008, you need to get an external component for that. Currently looking into what is available on the market, i'll get back to you with what i find.
Edit:
Ok had a look at both aspose.cells and OfficeWriter by SoftArtisans. Both claim to offer .xlsx-exporting capabilities for SSRS, but in both cases this is a partial truth at best.
Both work by having you recreate your report in Excel using their respective add-ons, and then pasting their own markup into your RDL-file. This also has the effect that if you are making an excel-exportable report in either tool, you won't be able to view or export it in anything else from SSRS. Both have the ability to open an existing report and access their datasets from there, which is a major advantage over trying to get MSQuery to work for you.
Aspose suffers from various issues with permissions on the server, where you need to grant it full trust (not everyone would want that). I also had a major hassle getting it installed properly.
OfficeWriter has some issues with shared datasources, where you generally have to go in and set them manually after you've published your report. It also seems to choke on VS2008 RDLs, if you want to use a dataset from a VS2008 report, you have to make a new report in VS2005 with your dataset, and use that as a basis for your excel-built report.
Personally I don't care much for either. But overall Officewriter does seem like it comes out ahead. Next stop is figuring out if it has built-in support for matrices, or that is something we would have to program in VB to get.
According to Exporting to Microsoft Excel(msdn)
The Excel rendering extension renders a report that is compatible with Microsoft Excel 97 and later.
This seems to suggest the old format.

Resources