How to do a mailing using a reporting tool? - winforms

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.

Related

Generate a series of documents based on SQL table

I am trying to formulate a proposal for an application that allows a user to print a batch of documents based on data stored in a SQL table. The SQL table indicates which documents are due and also contains all demographic information. This is outside of what I normally do and am trying to see if these is a platform/application that already exists to do such a task
For example
List of all documents: Document #1 - Document #10
Person 1 is due for document #: 1,5,7,8
Person 2 is due for document #: 2.6
Person 3 is due for document #: 7,8,10
etc
Ideally, what I would like is for the user to be able to push a button and get a printed stack of documents that have been customized for each user including basic demographic info like name, DOB, etc
Like i said at the top, I already have all of the needed information in a database, I am just trying to figure out the best approach to move that information onto a document
I have done some research and found some people have used mail merge in Word or using Access as a front end but I don't know if this is the best way. I've also found this document. Any advice would be greatly appreciated
If I understand your problem correctly, your problem is two-fold: Firstly, you need to find a way to generated documents based on data (mail-merge) and secondly, you might need to print them two.
For document generation you have two basic approaches: template-based and programmatically from scratch. I suppose that you will opt for a template based approach which basically means that you design (in MS Word) a template document (Word, RTF, ...) that acts as a template and contains placeholders and other tags that designate »dynamic« parts of the document. Then, at document generation time, you need a .NET library/processor that you will pass this template document and the data, where the processor will populate the template with the data and return the resulting document.
One way to achieve this functionality would be employing MS Words' native mail-merge, but you should know that this would involve using Office COM and Word Application Automation which should be avoided almost always.
Another option is to build such a system on top of Open XML SDK. This is velid option, but it will be a pretty demanding task and will most probably cost you much more than buying a commercial .NET library that does mail-merge out-of-the-box – been there, done that. But of course, the good side here is that you will be able to tailer the solution to your needs. If you go down this road I recoment that you use Content Controls for tagging documents/templates. The solution with CCs will be much easier to implement than the solution with bookmarks.
I'm not very familliar with the open source solutions and I'm not sury how many there are that can do mail-merge. One I know is FlexDoc (on CodePlex) but its problem is that uses a construct (XmlControl) for tagging that is depricated in Word 2010+.
Then there are commercial solutions. Again I don't know them in detail but I know that the majority of them are a general purpose document processing libraries. Our company has been using this document generation toolkit for some time now and I can say it covers all our »template-based document generation« needs. It doesn't require MS Word at doc generation time, and has really helpful add-in for MS word and you only need several lines of code to integrate it in your project. Templating is very powerful and you can set-up a template in a very short time. While templates are Word documents, you can generate PDF or XPS docs as well. XPS is useful because you can use .NET/WPF prining framework that works with XPS docs to print documents. This is a very high-end solution, but of course, the downside here is that it is not a free solution.

DB Comparison tool that I can schedule

I'm after a DB Comparison tool for SQL Server that allows me to do the following:
Schedule a comparison to happen on a recurring schedule
Email me the results (in a nice readable format and not the generated script)
Allow me to exclude/include certain object names (for example exclude table names containing %test%. That's not a real example but there is a good reason why that would come in useful.)
As well as the obvious:
Have the usual options for ignoring things like comments, identity seeds etc
Options for selecting different types of objects
If it was free or at least didn't cost a forture that would be an extra bonus of course.
I have tried out RedGate's SQL Compare and also the built-in DB Comparison in Visual Studio but neither seem able to do the first 3 points above. I also looked at other tools recommended in various threads on here but again they don't mention in their features the 3 points above.
One option I found is RedGate's SQL Comparison SDK with which I think I could write something to do what I want.
I just wanted to investigate tools that might do all of the above out of the box.
Thank you!
SQL Compare Pro comes with a command line, which will be easier to set up than the SDK. If you call this via the Windows Scheduler or in an Agent Job you can achieve what you're looking for.
An example of how to invoke the command line from Powershell it can be found here:
http://www.simple-talk.com/sql/database-administration/auditing-ddl-changes-in-sql-server-databases/
This article also covers how to send an email in Powershell. SQL Compare can also be passed a filter using the /filter switch to exclude objects based on various rules.
http://www.red-gate.com/supportcenter/Content/SQL_Compare/help/10.0/sc_cl_Switches_in_the_cl
Do please email support#red-gate.com should you have trouble getting this working.
I don't think any tool would do all of this out of the box. Have you had a chance to look at
sp_CompareDB. I had a similar requirement and ended up writing my own routine based on the same.
http://www.sql-server-performance.com/2001/database-comparison-sp/

What is best way to fill in data from database (sql server 2008) to word (word 2007 / template)?

I need to read data from my DB (MS SQL server 2008) and push them into Word document (Office 2007). What is the best and fast way to do it? I have read about the problem here : support.microsoft.com/kb/316384 and here : msdn.microsoft.com/en-us/library/aa192487(office.11).aspx. I have tried to understand also use of fleXdoc, but there is almost no documentation. I do not need to use it on server, i want generate locally. I will generate maximally 10 separate documents from template at maximum 5 pages per each. (Invoice for example). Please can someone point to some how-to or sample project, as i am unable to find something usefull. Thank`s a lot.
I suggest you output text files, CSV for example, and use those for your merge data files for Word.
You could use CustomXML databinding, but you will likely need to be able to handle repeating rows of data. That can be done (see http://dev.plutext.org/svn/docx4j/trunk/docx4j/sample-docs/databinding/conventions.html ), but may be overkill for your scenario.
What about making an HTML document for your data table, and including that in your Word document as an altChunk? See http://blogs.msdn.com/b/ericwhite/archive/2008/10/27/how-to-use-altchunk-for-document-assembly.aspx
Both of these approaches work with Word 2007 or later, using docx (Open XML) as the document format.
Something to be aware of however, the approach might not work with Office 2010. MS Had to remove a lot of the Custom XML merging stuff from Word as a result of a lawsuit about the technology. Updates to Office 2007 and definitely 2010 have some parts of that XML support removed.

Report viewer in wpf and selection formula

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?

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