Visual Studio 2010 calling SQL 2005 Reporting Services

I have SQL 2005 reporting services that host a couple of reports. In the past I’ve been able to access these report via a web page built in Visual Studio 2005. However, a recently created web application in Visual Studio 2010 has caused me some grief. I ran into issues with reports not being displayed, to JavaScript errors, etc.

Using the ReportViewer control in VS2010 allows running of remote SQL reports from report server 2008 and above This is where I ran into my first issue since my remote report was in SQL 2005 Reporting Services. Anyway, here is how I went about executing a SQL 2005 Report from a web page within Visual Studio 2010. Hope this helps.

1. From VS2010, create a new ASP.NET web application. By default this will target .NET Framework 4.

2. We will work with the "Default.aspx" page here. Open the page’s source code and add the following code just under the "page" directive.

Code Snippet
  1. <%@ Register Assembly="Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
  2.     Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>

3. Add the following code where you want the report displayed. I have a report named "MyReport" under a folder "Reports".

Code Snippet
  1. <rsweb:ReportViewer ID="ReportViewer1" runat="server" Font-Names="Verdana" Font-Size="8pt"
  2.     Height="400px" ProcessingMode="Remote" Width="400px">
  3.     <ServerReport ReportPath="/Reports/MyReport" ReportServerUrl="http://myserver/ReportServer$SQL2005&quot; />
  4. </rsweb:ReportViewer>

4. In the project references, add the reference to "Microsoft.ReportViewer.WebForms v2.0.5.727".

5. In Web.Config, add the following within the "System.Web" section.

Code Snippet
  1. <httpHandlers>
  2.   <add verb="*" path="Reserved.ReportViewerWebControl.axd" type = "Microsoft.Reporting.WebForms.HttpHandler, Microsoft.ReportViewer.WebForms, Version=, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
  3. </httpHandlers>

6. Run your web page in the browser and hope you see the report as I do.

Good luck!


Single row, multiple columns to variables in SSIS

The SQL Execute task in SSIS allows you to execute a SQL that would return a single row with multiple columns and then map these columns to variables within the package. To do this,

  1. In the General section set the Resultset property to “Single row”.
  2. Set the SQL statement.
  3. In the Result Set section, set the Result Name to 0 – n and the corresponding variables to be mapped. Ensure that the column order is right. I believe you can also use the column name but haven’t tried that.

Execute remote batch file from SQL job task

So I was asked if I could execute a batch file after an ETL was complete. The batch file to be executed resided on a remote server. The process currently involves a scheduled SQL job that first executes a SSIS package and then a stored procedure. Here are the steps I performed to be able to achieve this.

  1. On the remote server perform the steps as detailed in this Microsoft article Setting up Remote WSH.
  2. Create a BatToCall.bat batch file that will reside on the remote server. This is the batch file that we are going to execute remotely.
  3. Create a ExecuteRemotely.wsf script file. This script file will reside locally where the task is being executed but when called will perform the stated operations remotely.
  4. Create a Caller.wsf script file that will be called from the SQL job. This script file in turn will call the ExecuteRemotely.wsf script file.
  5. Create a SQL job with a step of type “Operating system (CmdExec)”. In the command, type “CScript Caller.wsf”. (The CScript command can be run from the command-line as well.)
  6. Execute the SQL job with appropriate permissions in place should execute the remote batch file.

Here is sample code for the above mentioned files.


echo | time > C:\ExecutedHere.txt


<script language="VBScript">
set oController = CreateObject("WSHController")
set oProcess = oController.CreateScript("C:\ExecuteRemotely.wsf", "\\RemoteServerName")
WScript.ConnectObject oProcess, "remote_"

While oProcess.Status <> 2
   WScript.Sleep 50
WScript.Echo "Done"

Sub remote_Error
    Dim theError
    Set theError = oProcess.Error
    WScript.Echo "Error " & theError.Number & " - Line: " & theError.Line & ", Char: " & theError.Character & vbCrLf & "Description: " & theError.Description
    WScript.Quit -1
End Sub



<script language="VBScript">
Dim WShell
set WShell = CreateObject("WScript.Shell")
WShell.Run "C:\BatToCall.bat"
Set WShell = nothing

Unable to execute SSIS packages containing script tasks developed in 32 bit and deployed in 64 bit environments

I started to run into this error in the last month or so. I’ve been developing SSIS 2005 packages on my desktop which is an XP Professional and deploying them to Windows Server 2003 R2 Enterprise x64 edition. All was well until recently, according to Microsoft one of the updates broke compatibility on a dll and caused this issue (More details here in the Microsoft KB 931846). There were a few suggestions such as open the packages on the target server and make an update and save them to force recompile. This is not fun when you have multiple packages and in some instances did not do the trick.

My solution which has worked consistently so far is to restart the Integration Services after you deploy the  updated packages on the target server.

Dynamic SQL in SSIS Data Flow task

The Data Flow Source in the Data Flow tab extracts the metadata from the source to populate the column information. In the case of a stored procedure that uses dynamic SQL within, this can pose a problem in getting the metadata. Depending on the situation here is one way to get around the issue. Below is sample stored procedure that works with the pubs database. Comment the mentioned block in the stored procedure to see the difference in the SSIS package.

With the block commented, the Data Flow Source does not have any columns to extract and map. With the dummy block in place the Data Flow Source extract the required metadata to display columns. Note that the code block will not execute at runtime but it allows you to call a stored procedure with dynamic SQL in it from the Data Flow source in a SSIS package.

    CREATE PROCEDURE [dbo].[GetAuthorsByState]
        -- Add the parameters for the stored procedure here
        @States varchar(10)
        -- SET NOCOUNT ON added to prevent extra result sets from
        -- interfering with SELECT statements.

        DECLARE @strSQL nvarchar(1000)

        -- Start of the block to enable the Data Flow source to work
        -- Comment this block to see the effect on the Data Flow source in the SSIS package
        IF 1 =2
            SELECT [au_id]
            FROM [dbo].[tblAuthors]
        -- End of the block to enable the Data Flow source to work

        SET @strSQL = '
            SELECT [au_id]
              FROM [dbo].[tblAuthors]
            where state = ''' + @States + ''''

        EXEC dbo.sp_executesql @strSQL


SQL CONVERT function and SQL dates

I recently had a colleague stop by asking how he could eliminate the time portion of a date when he extracted the data from a SQL table to MS-Excel. He was having trouble grouping dates in Excel because the data contained the time part as well. My first thought was using DATEPART but my wonderful DBA team member Mary T. suggested using the CONVERT function with the style 101. Worked out perfectly. Here is a sample code displaying the results. There are other styles as well with the CONVERT function.

	CONVERT(varchar(10), [OrderDate], 101) AS JustOrderDate 
FROM [Northwind].[dbo].[Orders]


OrderDate                                  JustOrderDate
1996-07-04 00:00:00.000        07/04/1996
1996-07-05 00:00:00.000        07/05/1996

SSIS packages, configuration settings and multiple servers

When I started building SSIS packages I frequently ran into the issue of having to maintain configuration files across different environments. The way I handled it was to use SQL server as the storage place for my package configuration. With that comes the need to be able to point to the appropriate SQL server and database depending on the environment or server. This is where the environment variable comes in handy. With that being said here are the steps to create a package and associated elements to accomplish a flexible configuration setup across servers.

  1. Setup the configuration database. The configuration table can reside in an existing database or in a new one. For this exercise let’s create a new database called “ConfigDB”.
  2. Create an environment variable “SSIS_CONFIG_DB” and set the value to the ConfigDB database. For example, Data Source=MySQLServer;Initial Catalog=ConfigDB;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False; 
  3. Set the connection string to the ConfigDB from the environment variable.
    1. Create a new package.
    2. Create a new variable called “EnvName” as a string. You can set the value to “Development”.
    3. Create a new OLE DB connection and set the connection to the ConfigDB database.
    4. Open the Package Configurations window.
    5. Check the Enable package configurations.
    6. Click the “Add…” button to start the Package Configuration Wizard.
    7. Choose “Environment variable” and then select the “SSIS_CONFIG_DB” variable from the dropdown.
    8. For the target property, select the ConnectionString for the above created connection manager and then click Next.
    9. Assign a name for the configuration and finish.
  1. Generate and save configuration settings.
    1. Open the Package Configurations window.
    2. Click the “Add…” button to start the Package Configuration Wizard.
    3. Choose “SQL Server” in the Configuration Type.
    4. Select the database connection to the ConfigDB and choose the default configuration table name “SSIS Configurations”.
    5. Enter “MySQLConfig” in the Configuration Filter. This could be any meaningful name.
    6. Click the Next button.
    7. In the objects locate the variable “EnvName” and check the Value option.
    8. Click Next, and then give a name to the configuration. For example, “Init_Settings”.
    9. Click Finish to generate the configuration settings and then close.
    10. To verify that the settings have been created, look at the table rows for “SSIS Configurations” in the ConfigDB database. There should be a row with the ConfigurationFilter “MySQLConfig”.
  1. To verify the working of this setup create a Script task to display the value of the variable EnvName. Make changes to the variable in the ConfigDB database and will see it reflected in the package execution.
  2. Moving to another server. To have this package run in another server with different EnvName values follows the steps below.
    1. Generate the SQL script for database and table from the original ConfigDB and recreate it on the new server.
    2. Copy  the row from the original configuration table “SSIS Configurations” and paste it in the new table and modify the ConfiguredValue for the variable EnvName.
    3. Setup the environment variable “SSIS_CONFIG_DB” with the value set to the connection string to the new configuration database. For example,  Data Source=MyNewSQLServer;Initial Catalog=ConfigDB;Provider=SQLNCLI.1;Integrated Security=SSPI;Auto Translate=False; 
    4. Copy the SSIS package to the new server and run it. You should see the value from the new server displayed.



I’ve used this method to move my packages from development to QA to production with minimum to no changes to configuration settings. I also use this to turn on and off logging modes in the different environment to debug packages.