Category Archives: Uncategorized

The following video shows how you can create a simple RDL report, deploy it to the Report Server, and view it from the Report Manager in SQL Server 2008 Reporting Services: Video 1 – Create a simple server-side report in Reporting Services. Video 2 – Export a server-side RDL report from a .NET Windows Application. Report.cs (6.76 kb) to download Report Class that’s used in video 2. Click NunoSolutions.7z (69.20 kb) to download the sample project used in the video 2. One more thing, make sure to update the user credentials with an user that has access to run reports.

The following code was written and tested against SQL Server 2008 R2 Reporting Services. The helper classes help reduce and simplify the amount of code you’ll have to write (and remember) when exporting reports from SRS. I included the ReportExecutionService proxy class that I generated using the WSDL.exe tool. However, you can add a web reference to it using the GUI tools in VS.NET. For those of you who are interested in the command I used: Open the Visual Studio 2010 Command Prompt (it should be located in Start>All Programs>Visual Studio 2010>Visual Studio Tools>Visual Studio Command Prompt) and enter the following:   ·         C:\wsdl http://localhost/reportserver/reportexecution2005.asmx     Here’s what the code will look like to export a report: NunoSolutions.Report rpt = new NunoSolutions.Report(); rpt.ReportServerUrl = http://localhost/ReportServer; // Change localhost in this path to your server’s name rpt.ReportTitle = “My Northwind Customers”; // This value is used as the file name…

Read more

  A new Clause was introduced in SQL Server 2005 called “OUTPUT” that enables you to do some pretty cool stuff. For example, let’s say you wanted to create an audit table and wanted it updated each time a query executes an INSERT or UPDATE statement (works with DELETE too) but you don’t want to create a Trigger in your table. This is the perfect scenario where you could use the OUTPUT clause. In the example below, I created a table named employee and an audit table named emp_audit that I’ll be using to store a copy of successfully affected row values from the employee table anytime an INSERT and/or UPDATE is executed:     CREATE TABLE employee(       emp_id int IDENTITY(1,1),       first_name varchar(20),       last_name varchar(25),       address1 varchar(50),       Primary Key (emp_id) );   CREATE TABLE emp_audit(       emp_id int,       first_name varchar(20),       last_name varchar(25),      …

Read more

The following code allows a developer to convert a DataTable into a MemoryStream so that it can be attached to an e-mail. It accepts a DataTable and binds it to a GridView. Next, it renders the GridView into a StringWriter object. To convert a string into a byte array I used the Encoding object and wrote the byte array into the MemoryStream. Attaching the MemoryStream to an email is easy. Read the usage snippet below. Usage: DirectExcel excel = new DirectExcel(); System.IO.MemoryStream ms = excel.ExportToStream(myDataTable); Attachment attachFile = new Attachment(ms, “filename.xls”, “application/vnd.ms-excel”); MailMessage mail = new MailMessage(); mail.Attachments.Add(attachFile);     In order for the above snippet to work, you will need to copy the ExportToStream method below and paste it in your DirectExcel Class. If you don’t already have a DirectExcel Class click here to copy it from my previous post.   public System.IO.MemoryStream ExportToStream(DataTable objDt) {     //remove any…

Read more

Before I begin this article I want to make sure it’s clear that I created this code a few years ago based on research I found on Google and MSDN (so I can’t take full credit for the implementation). This version of the code is customized and encapsulated in a standalone class. I believe this to be extremely useful for many developers out there.   If you’ve used SQL Server Reporting Services you know that printing a report programmatically isn’t as easy as calling ReportServer.Print(). This is why I put together a class that provides this functionality. The amount of code you have to write to print a report via the SQL Reporting Services Web Service can be a mind blowing task. Before we go any further, here is a link to the RSPrintManager class.   The first thing you’ll want to do is Add a Web Reference to your…

Read more

The following sample is great if you want to load an Employee or signature image from your database. I tried to comment it as much as possible so I think the code will be self explanatory.   // Load an image into a PictureBox from a SQL Server image datatype public void LoadImage(PictureBox pic) {     // TODO: change connection string     SqlConnection con = new SqlConnection(“Data Source=<server>; Initial Catalog=<YouDatabaseName>; Integrated Security=SSPI;”);     // TODO: change query to pull form your own tables     SqlCommand cmd = new SqlCommand(“select top 1 signature_jpeg from SignOffForm where order_id = @order_id”, con);     SqlDataReader rdr = null;     byte[] imgData = null;     try     {         int orderID = 10000;         cmd.Parameters.AddWithValue(“@order_id”, orderID);           con.Open();         rdr = cmd.ExecuteReader(CommandBehavior.CloseConnection);         if (rdr.Read())         {             // make sure our byte array is big enough to store the image             imgData = new…

Read more

WMI is a powerful tool provided by Microsoft that provides component information and notificaiton. Below is a snippet on how you can query WMI to retrieve the Dell Service Tag of a single computer. You can easily extend this sample via Directory Service (LDAP) to query all PCs in your network. Please Note:  Make sure you add a reference to System.Management and place using System.Management; to the top of your code file. We start by setting the computerName string to you PC’s name. You can press and hold window key on your keyboard then press the Pause/Break key to load the System Properties . If Windows XP you’ll want to click on the Computer Name tab. On Windows 7/Vista machines you will see the computer name right on System window that pops up somewhere near in the middle of the screen. string computerName = “<Your PC Name>”; Next you’ll want to create a ManagementScope object by…

Read more

A co-worker (Rob Yacullo) and I wrote the following utility to help us figure out which directories consumed the most drive space. With this tool you can easily figure out which directories are consuming high amounts of disk space without having to drill down each individual directory in Windows Explorer. The following link is the executable only: Folder Sizes The following link contains the full source code: Folder Sizes Source This applicaton was built on top of the .NET Framework 3.5. Enjoy! -Nuno

Often in the web world developers are asked to add Excel exporting capabilities to their web application or web services. The following demonstration shows you how you can implement a decent solution that is both quick and easy to implement in you own code. I built a class named DirectExcel that inherits the ASP.NET GridView control. The reason it inherits the GridView is because this exporting technique requires that our data be databound to a grid. First lets take a look at a snippet of code on how we can use this class.   Usage Snippet: SqlCommand oCmd = new SqlCommand(“usp_get_data “); oCmd.CommandType = CommandType.StoredProcedure;  // The report name will also be used as the filename when saving. DirectExcel directExcel = new  DirectExcel(“Report Name”);  // oCmd is a SqlCommand that contains the Query you want executed against the database  directExcel .Export(oCmd);   You will need to add a connectionString key to your web.config…

Read more

This is an example page.  For more information about pages and how to use them, visit the BlogEngine.NET wiki.

30/30