Prevent A Same SSRS Report From Running Concurrently

Some report could have quite long run more then some minutes. Usually due to heavy query or big content.
This blog will show how to prevent a specific SSRS report to have two or more report instances being run in same time.
So it applies only to each report you want to validate.

Creating Class Library

First, you need to make a class library either using VB.Net or C# and add a Web Reference to SQL Server Reporting Service API.
This class library is intended to list all active SSRS report jobs.

  1. Create a VB.Net Class Library Project and save it as SSRSLib.vb
  2. Add Reporting Service Web Reference.
    To do that, click Add Service Reference, Advanced, Add Web Reference.
    Inside Url text box type http://yourServIpAddr/ReportServer/ReportService2010.asmx for SSRS 2008 R2 version, click ‘go’ arrow icon.
    Edit the Web Reference Name to your prefer i.e ReportService2010 and then click Add Reference button.
  3. Write a class to retrieve list of SSRS Active report jobs
    Public Class SSRSInstance
    Public Sub New()
    
    End Sub
    Public Function getJobs() As DataTable
    	Dim dt As New DataTable()
    	dt.Columns.Add("JobID")
    	dt.Columns.Add("Name")
    	dt.Columns.Add("ComputerName")
    	dt.Columns.Add("UserName")
    	dt.Columns.Add("Action")
    	dt.Columns.Add("StartTime")
    	dt.Columns.Add("Status")
    
    	Dim rs As New ReportingService2010()
    	rs.Credentials = New System.Net.NetworkCredential("yourUserId", "yourPwd")
    	Dim jobs As Job() = Nothing
    	jobs = rs.ListJobs()
    
    	Dim job As Job
    	Dim dr As DataRow
    	For Each job In jobs
    		dr = dt.NewRow()
    		dr("JobID") = job.JobID
    		dr("Name") = job.Name
    		dr("ComputerName") = job.Machine
    		dr("UserName") = job.User
    		dr("Action") = job.JobActionName
    		dr("StartTime") = job.StartDateTime
    		dr("Status") = job.JobStatusName
    		dt.Rows.Add(dr)
    	Next job
    
    	Return dt
    End Function
    End Class
    
  4. Build your project. Since my assembly named SSRSLib so that build project will produce two dll files which are SSRSLib.dll & SSRSLib.XmlSerializers.dll
  5. It is better to test your class Lib with Console Application before proceeding any further to know whether it contains error or success

Okay first step has done. The SSRS list jobs class library is created. Usually the class library created for SSRS called custom assembly.
Continue reading

Multi Tier PHP Application Using RabbitMQ, Web & Worker Architecture

Large Web application needs to have some strategy to ensure web run smoothly. It is also intended to avoid Server down on busy hours.

Imagine thousand to million hits your Server simultaneously. Application could be down even with great hardware specs.
In Hardware point of view, you can do Load Balancing, Traffic Manager, Scale out by adding more Virtual Machine or Scale in by getting higher specs i.e CPU, Memory, HD.
The infrastructure setup is even easier using popular Cloud Portal available widely in market i.e Ms Windows Azure, Amazon Web Service, Google Cloud Platform.
You don’t need to have physical servers on your room. Cloud Portal has menu to create VMs and there are several CPU, Memory, Storage specs options. More high the specs then more costly.
Also you can do Load balancing, Auto/Manual Scaling, Traffic Manager with just some clicks on the Portal.

However considering only H/W and infrastructure sometimes is not enough.
You don’t want to be forced urgently to add more VM or increase H/W specs just because actually you are not managing your application or software properly.

Modern enterprise application use Multi Tier architecture. They use Web and Worker tier for handling users request. On back end side there are database and storage tier.
Web tier contains user interface i.e html body, event handler, etc. Worker is a background process that continuously run and usually used to process jobs which require more computational resources asynchronously .
The main purpose to have web & worker tier is to avoid requests burden application too busy and further more causing your server not responding.

Lets say we have an incident example. There is a web app which has reporting feature sent to user in PDF format. Many clients request for reports simultaneously and those requests are directly processed by database server on same time.
Also after data is retrieved, the Web tier creating many PDF based on requests and send them to clients by email.
Slowness will occur and thus Server either web tier or database will not responding. Not to mention if web tier and database is in one VM only.
You need to stop requests by killing them or just restart the server.

This case is a good example for explaining the need of Worker. So Web tier will sent user request by writing a message to Message Queue instead of sent requests directly to back end or database tier.
Message Queue is just text stored in a Message broker and it has FIFO (First In First Out) for write & read those messages. In this scenario, Web Tier write a request as message to Message Queue
Worker instance that run continuously on background reads client request or message from Message Queue and creating PDF report. The PDF report creation will be sequential based on FIFO of message queue.
So only one report processed in a time for one Worker instance. Lets say you want more report generated in time then you can generate another Worker instance. So you have two or more Workers.
You can manage how many workers you can have based on Server performance.

After Report is generated either that Worker which auto send the report or you may create another Worker to do it.
So first Worker that generate report will write a message to Queue when report is done. Second Worker read a message and send the report.

Below is the schema of multi tier application with Web & Worker Tier.

It is a common scenario and also as a tutorial example in internet since it is understandable with ease.

However this blog post source code is not presenting above schema.
This time we assume for having a Photo Web App and it has more than thousands hits every day like Instagram. This example will retrieve list of photos of followed persons / owner.
Since the Web app hits is quite heavy then we need some strategy using multi tier application.

Basic method to retrieve an image is to download it from database via Web tier and show it to browser. We won’t do that way. We will use Worker to retrieve photos from DB and store them to file storage.
Web tier will show those photos to client browser. The communication between Web & Worker tier use Message queue i.e RabbitMQ.

Please look the schema below:

The difference for this case is the Message Queue has ‘reply-to’ feature. So every request will be replied through Message Queue to ensure Web tier (client) get response immediately after photos are generated.

Many Message Queue available on internet but I use RabbitMQ because of easiness to install and easy to code also.
If you have not familiar yet with RabbitMQ then I suggest you to go to this Url: https://www.rabbitmq.com/getstarted.html and install it to your PC/laptop/dev server.
There is also nice step by step tutorials so you can go through it.
Continue reading

Adapter Pattern OO Design PHP Example

Quoting from Url http://www.oodesign.com/adapter-pattern.html
“The adapter pattern is adapting between classes and objects.
Like any adapter in the real world it is used to be an interface, a bridge between two objects.
In real world we have adapters for power supplies, adapters for camera memory cards, and so on. Probably everyone have seen some adapters for memory cards. If you can not plug in the camera memory in your laptop you can use and adapter.
You plug the camera memory in the adapter and the adapter in to laptop slot. That’s it, it’s really simple.”

It is more clear to understand with example.
PHP Examples

  1. Example 1
    class clsSong {
    	private $title;
    	private $genre
    	function __construct($title, $genre) {
    		$this->title = $title;
    		$this->genre = $genre;		
    	}
    	
    	function getTitle() {
    		return $this->title;
    	}
    	
    	function getGenre() {
    		return $this->genre;
    	}
    }
    
    class clsSong_Adapter {
    	private $objSong;
    	function __construct(clsSong $objSong) {
    		$this->objSong = $objSong;			
    	}
    	
    	function getTitleGenre() {
    		return $this->objSong->getTitle()."/".$this->objSong->getGenre();
    	}
    }
    
    //implementation 
    $objSong = new clsSong("Nothing Else Matter", "Heavy Metal");
    echo $objSong->getTitle()."/".$objSong->getGenre();
    echo "<br>";
    
    $objSngAdapt = new clsSong_Adapter($objSong);
    echo $objSngAdapt->getTitleGenre();
    
    

    Continue reading

DB2 Export Data To CSV With PHP Interface

Reporting with large number of records could be cumbersome if you view it on web page and download the data to CSV or Excel format.
Especially if you are dealing with hundred thousand or millions records.

DB2 has feature for export data or download records directly to external storage i.e your local hard disk.
The way is to specify the data to be exported by supplying an SQL SELECT statement and then use db2 export to download directly to CSV format.

The DB2 syntaxt for this download is db2 export to <filepath/filename> of del <SQL Select statement>.
More complete explanation please go to IBM url https://www.ibm.com/support/knowledgecenter/en/SSEPGG_11.1.0/com.ibm.db2.luw.admin.cmd.doc/doc/r0008303.html

This blog post will explain how to use DB2 export with PHP.
The PHP page calls DB2 export which transfer records to CSV format and after file created and finish transfering then the CSV is zipped.
Continue reading

PHPPageNo Class For Easy Page Numbering Creation

PHP

Brief

PHPPageNo Class helps you to implement page numbering in your PHP application.
This class shows Page No with links to navigate the Page’s Url.
The class constructor have four value settings that you can adjust like $startRec which represents starting record,
$totalRec is total records, $maxRecPerPage is a maximum no of records per page and $maxPageDisplay is a maximum no of page shown.
Anyway you should understand basic of OOP in PHP like constructor, class extends etc in order to get the idea of this post.

The screen shot of how PHPPageNo works is below:

Resulted Page No are also includes Prev and Next links if the total page query is more than $maxPageDisplay.
This makes the page numbering would not be shown like blown list of page no.
Continue reading

Upload file to Azure Cloud Storage Via Asp.Net Web App

windows_azure

Intro

Micrososft WindowsAzure is a rock solid Cloud platform that enables you automatically scales in/out your web application.
Not only scaling capabilites but also storing your files whether they are big or small in Azure Cloud Storage makes your mind free from conserning your own reliable storage on premise.
I give you basic example how to upload a file to Azure Cloud Storage via Web App using Asp.Net C#. Also to provide a link for user to download that uploaded file.

Create Storage Account or Use Local Development Storage

If you are still under development and run the web app under local PC/Laptop then you can use Development Storage.
Install necessary Azure SDK using Visual Studio 2013 or 2015 or Microsoft Web Platform Installer. After the installation done you should have Compute Emulator and Storage Emulator.
The storage emulator must be started properly before hand in order to run your Storage application in your local environment.

To access your storage you must supply Storage Connection String. Since we are using local environment then the Storage Connection String is UseDevelopmentStorage=true.
Please pay attention of it is a case sensitive.

After you finish your development and want to publish it on the cloud then you must register for Storage Account withing Azure portal and change your Storage Connection String properly in your code or configuration file.
Continue reading

Core Benefits Using Public Cloud Service Rather Than On Premise

We already introduced to Cloud Technology that leverage Virtualization to minimize physical Servers cost.
Technically, there are some schemes in Cloud which are Public Cloud, Private and Hybrid. Private Cloud has its own Data center, virtualization & infrastructure on premise whereas Public cloud are over the Internet.
On the other hand, Hybrid Cloud is in between your on premise and public cloud. Hybrid used to integrate existing On premise With public cloud features.
This blog focus on Public cloud pros and cons.

Public cloud itself devided into three categories which are Infrastructure as a Service (IaaS), Platform as a Service (Paas) and Software as a Service (SaaS).
Example of IaaS are Virtual Machine as a Server, Virtual Network, Cloud Storage etc. PaaS are Scalable Web App Hosting, Database as a Service etc.
SaaS are GMail, GDrive, Office 365, One Drive, Amazon Document Sharing, Drop box etc.
There are three major companies provide Public Cloud services: Microsoft Azure, Amazon Web Service and Google Cloud.
Below are pros and cons using Public cloud for your organization.

Benefits:

  1. Up time guarantee. Your application, data, servers, virtual networks are inside Data Centers and its Infrastructure provided by those great companies.
    Your account include SLA that guaranteed the system will be online 24/7 for a whole year. Ensuring reliability and availability is important and the most important thing is to make us having Peace of Mind
  2. Your Application and Servers are Available over the Internet with secure access Control.
    You can access your system anywhere but if you want to limit by specific IP range surely you can.
  3. Continue reading