Monday, June 17, 2013

Project Management through Pictures
What is Brainstorming?

Brainstorming is a method or tool in which a project team sits and talks about all kind of ideas to solve a specific problem. It is a great platform to develop and motivate a team.

There are lot of great articles flowing in the cloud which talks about what it is, how to do it and other stuff on this. I believe a picture tells a better story then text. So here is my pictorial representation of Brainstorming.

Brainstorming is such a tool that you can use in any phase of Project Management but mainly this is used in Planning phase.

Thursday, June 13, 2013

Google App Script to get Stock Price in your inbox Every hour

Google App Script is a nice platform to automate the task that you do using different Google products and services such as Gmail, Drive, Calendar, Spreadsheets etc

In our last post we learn how we can start writing Google App Script. We develop a script which will read the email message count from our Gmail inbox. In this post let us create a script which will pull the stock price of shares from Google finance and send it to us through email.

To start with we need to go to http://script.google.com, and create a blank project. We can write the below script code which pulls the share prices of some of the stocks such as Reliance Industries, Maruti Suzuki and Coal India. All we have to do is to pass the Stock symbol of the share to FinanceApp.getStockInfo() function. You can get the stock symbol of any share on Google finance or on moneycontrol.com or on any website which provide the stock price and its details. The share prices are then email to the user email address.

function myFunction() {
  
  var info = FinanceApp.getStockInfo("500325")
  var strMsg='Share Price of ' + info.name + ' is : ' + info.price + ' || '
  
  info = FinanceApp.getStockInfo("MARUTI")
  strMsg=strMsg + 'Share Price of ' + info.name + ' is : ' + info.price + ' || '
  
  info = FinanceApp.getStockInfo("COALINDIA")
  strMsg=strMsg + 'Share Price of ' + info.name + ' is : ' + info.price + ' || '  
  
  
  var sentEmailTo="singhvikash.blogspot.com@gmail.com"
  GmailApp.sendEmail(sentEmailTo, "Portfolio Status" , strMsg) 
  
 
}

Now let us create a trigger which is kind of a scheduler where you setup how and in what frequency this script will be executed. For this we need to go to Resources->Current project’s triggers

This will show the triggers that are setup on this current project/script. If there are no triggers setup, we need to click on add one now.

It will show the current project triggers page. We need to select our function name. To setup this script to run every one hour, we need to select Hour timer and Every Hour. To save the settings we nee to click on Save.

That is all we have to do. Now, every hour you will get the stock prices in your email.

This is very useful where you do not have access to internet or do not have access to see the stock prices. You can use any valid email address to send the stock prices. The script will send the stock prices every hour.

This is very useful where you do not have access to internet or do not have access to see the stock prices. You can use any valid email address to send the stock prices. The script will send the stock prices every hour.

How to get started with Google App Scripts?

Uses of Macros and Scripting are very common when you deal with Ms-Office products such as Ms-Excel, Ms-Word, Ms-Access etc. With macros you can automate a lot of task that you do repeatedly with excel, word etc. What Google App Scripts provide you is ability to create macros and script in cloud using JavaScript cloud scripting language and leverage the use of Google products and services such as Gmail, Google Drive, Spreadsheet, Google Analytics, Calendar etc.

You can create scripts which can access your gmail, goolge drive, spreadsheet, calendar etc and provide you information and statistics that you can use in your daily life. The Google App Script are developed using Google App Script editor which is a browser based tool. The scripts that you developed are stored in cloud to your Google Drive. The good thing is unlike Google Data API, you do not need to download and install libraries to your desktop.

The pre-requisite to create Google App Script are following:

1. You need to have a Google Account. If you do not have one you can create a new Google account.

2. You need a web browser which is compatible to develop Google App Script. For a list of supported browser you can visit this link.

3. You need to enable JavaScript and Cookies in your web browser.

4. A basic understanding of JavaScript scripting language.

5. Internet connectivity on your desktop.

To develop your Google App Script you need to go to http://script.google.com, This is the place where you will develop and test your Google App Script.

You will get the following screen and you can select what kind of script you want to create. You can choose a Blank Project if you want or select Gmail, Drive, Calendar, Spreadsheet project. It also let you open an existing Google App Script project.

Let us select Gmail to create a simple script which will tell us how many new messages and spam messages we have in our Gmail account.

The default script page that you will get is following:

Let us delete the entire code and add following scripting code in the script editor.

/**
* Author  : Vikash Kumar Singh
* Purpose : This script send new and spam message count to any email address
*
*/

function processInbox() {  
  var NewMessageCount = GmailApp.getInboxUnreadCount();
  var SpamMessageCount=GmailApp.getSpamUnreadCount()
  var sentEmailTo="singhvikash.blogspot.com@gmail.com"
  var myMessage="Total New Message in your inbox is:" + NewMessageCount  + " || "
  myMessage  = myMessage + "Total Spam Message in your inbox is:" + SpamMessageCount
  GmailApp.sendEmail(sentEmailTo, "Today Gmail Status" , myMessage) 
 
};

Click on Save button and it will ask to provide name to your project.

Click on OK. The script file will be saved.

Next, click on the Run button to run the project.

This will ask for Authorization for the first time.

Click on Authorize. It will open another window to ask you to Grant access. Click on Grant Access.

Authorization and Grant Access is one time activity for the Script project to run. Next you will get to see the Authorization Status. You can close the window.

Next click on Run and if you do not get any error message, you can check you inbox and you will receive an email with your new and spam message count.

Tuesday, June 11, 2013

NOW, send up to 10 GB of files through attachment using Gmail

Gmail is one of the most popular email services on internet. With its continuous effort to make email services better and better for the users, it has won trust for millions of users across the Globe.

One of the feature that Gmail has introduced is it has remove the limitation of sending attachment files of up to 25 MB through emails. Now, you can send the files that have size up to 10 GB through Gmail. All you have to is to use the new Compose Mail feature.

When you use the new Compose mail feature you will find a small icon in the bottom of the window with the name "insert files using Drive" which you can use to send files which are larger than 25 MB and smaller than 10 GB. Basically what Google has done is it has integrated Gmail with Google Drive. So all you have to do is to upload your files to Google Drive. You can upload the files using Gmail Compose mail or by going to Google drive. The point is your file should exist in Cloud i.e. on Google Drive.

When you click on the Insert files using Drive button, it will open a Google Drive window. From this window you can either upload the file or select an existing file that you have previously uploaded into Google drive.

you click on Insert button, the files will be attached to your Gmail message that you are drafting.

That is all you have to do. Now when you click on Send button, Gmail check who are the recipients of this email message. If recipients are not gmail user, you can select option like Anyone with the link. If the recipients are gmail users you can select Recipients of this email.

That is all you have to do.

When the recipients receive your email and they will see the attachments link in the email message.

They can click on the email and can see the files. The good thing is once you have sent the email and latter you want to modify the files, you can go to Google drive and update your files. You do not need to send the email message again.

SSRS: How to run SSRS reports on a Web Page?

Reports are integral part of any business solution. To show reports in an ASP.NET web page we can follow the below steps.

1. Develop the SSRS using BIDS (Business Intelligence Development Studio) or Report builde or VS-2012.

   
2. Deploy the SSRS report to the report server.
   
3. Create a web site project in Visual Studio. Open an ASP.NET page in design mode.
   
4. Add a Script Manager component from the Toolbox -> Ajax Extensions to the page.
   
5. Add a Report Viewer component from the Toolbox -> Reporting

   
6. Select the Reportviewer Tasks and set following properties

a. Choose Report = Server Report
b. Report Server url = http://localservername/ReportServer
c. Report Path = /ReportFolderName/ReportName, for example if my reports are in Sales folder and report name is productSale then Report Path is /Sales/productSale. Note we do not add report extension (.rdlc) with the report name.

That is all you have to set in Visual Studio. Run the web project solution and you will see the reports are loaded on the ASP.NET page.

How to check whether a Website is up or down?

Everyone at some point of time has faced that their favorite website or webpage is not accessible. Do you wonder how you can check whether the site is up or down really? Is this down for your only or for the across globe.

www.isitdownrightnow.com is a great tool available on internet to check the status of a particular web site. All you need to is to enter the website name and it will use its online website checker tool to check on the website and provide status.

I checked the status of www.SinghVikash.in and here is the status for the same.

The good thing is it has a section where it shows the list of websites which are currently down.

Source: http://www.isitdownrightnow.com

Sunday, June 9, 2013

SSIS: How to extract/unzip files to a folder using 7-Zip?

This post will show how we can extract contents of a zip file using 7-zip with SSIS.

7-zip is a good tool to zip, compress and extract files and folders. In case you have a requirement to compress/zip the files or extract a zip files received by a customer, you can do this easily with SSIS.

I have previously posted an article on How to zip/compress you files using 7-zip, in this post we will explore how we can do the vice versa that is how to unzip a files.

The steps in SSIS are simple to follow. Let us say we have a zip file called xyz.zip that is located in our hard disk. To unzip this with SSIS we have to create a package. In the package let us add Execute Process Task.

In the Execute Process Task set the Executable property to the C:\Program Files\7-zip\7-zip.exe or whatever location your 7z.exe is installed.

In the Arguments you can write x [Zip File Location] -o[Destinatin Folder Location]. For example if your zip file is in D drive and you want to extract the contents of this zip file to temp folder you can write argument like D:\xyz.zip -oD:\temp.

That is all you need to do. You can add your own creativity to make it more dynamic but I hope the concept is clear.

Keep this in mind, if the files already exists in the destination folder, a command line window will pop-up during package execution to confirm about the overwrite of files.

To Know more about the arguments of 7-zip that you can use with SSIS, you can follow this excellent page at dotnetperls.com

Friday, June 7, 2013

SSIS: How to load multiple excel files into multiple SQL tables?

SQL Server Integration Services (SSIS) is a powerful ETL tool to extract, transform and load data from multiple sources. In this post we will see how we can SSIS to extract/read data from multiple excel files and load it to multiple SQL tables.

To start with let us consider we have three Excel files with different columns and rows of data into them. Our target is to read data from each of the excel file and load them in their respective SQL Table.

Let us create three SQL tables which will store the data from these Excel files. The important point to consider is we will keep the table name same as Excel file name, this is just because we want to keep this example simple and straight forward.

SQL table Products

CREATE TABLE [dbo].[Products](
    [productName] [varchar](100) NULL,
    [quantity] [int] NULL
) ON [PRIMARY]

SQL table Emp

CREATE TABLE [dbo].[emp](
    [empName] [varchar](50) NULL,
    [empAge] [int] NULL
) ON [PRIMARY]

SQL table Dept

CREATE TABLE [dbo].[Dept](
    [DeptCode] [varchar](50) NULL,
    [DeptName] [varchar](50) NULL
) 

Next we are creating a stored procedure which is heart of this solution. In this stored procedure we have written logic to load the data from excel files to SQL tables.

The stored procedure has one parameter @ExcelFileName in which we will pass the full qualified name and location of excel files. The stored procedure uses T-Sql function OPENROWSET to to load the data from excel file to sql table. As you know OPENROWSET function can read data from multiple sources such as excel csv, text files, sql tables, oracle etc.

In the Stored procedure we have extracted the table name from the supplied excel file; this is because we have kept the table name same as Excel file name.

If you have never used OpenRowset before you need to consider two points.

  • This function is not available by default in SQL Server. To enable this function you have to enable the ad hoc distributed queries. You can run the following statement in Query Analyzer to enable this functionality.

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO

In case you are getting error after executing the above statement, I would recommend you to visit this post written by Michael Aspengren to resolve your error message.

  • After you successfully execute this statement, you need to ensure that the SQL Server services are running under Local System account or at the minimum the account that is running your SQL Server services is part of administrator group. If not you can change that and restart your SQL Server services. If your SQL Server is already running under Local System account you can skip this step 2.
CREATE PROCEDURE ExcelToSQLTable2
    @ExcelFileName nvarchar(100)
    
AS
BEGIN

DECLARE @stringSQL nvarchar(500)
DECLARE @SQLTableName nvarchar(500)
   
   /*************************************
   Extract Table Name from Excel sheet
   *************************************/
    SELECT @SQLTableName=reverse(@ExcelFileName)
    SELECT @SQLTableName= reverse(SUBSTRING(@SQLTableName, CHARINDEX('.',@SQLTableName),((CHARINDEX('\',@SQLTableName))-CHARINDEX('.',@SQLTableName))))
    SELECT @SQLTableName=SUBSTRING(@SQLTableName,1,LEN(@SQLTableName)-1)
    
    
    SET @stringSQL='INSERT INTO ' + @SQLTableName + ' SELECT * FROM OPENROWSET('
    SET @stringSQL=@stringSQL + CHAR(39) + 'Microsoft.Jet.OLEDB.4.0' + CHAR(39) + ',' + CHAR(39) + 'Excel 8.0;Database=' + @ExcelFileName + ';' + 'HDR=YES' + CHAR(39) + ','
    SET @stringSQL=@stringSQL + CHAR(39) + 'SELECT * FROM [Sheet1$]' + CHAR(39) + ')'
    
    EXECUTE sp_executeSQL @stringSQL
    
    SET NOCOUNT ON;

    
END
GO

Coming back to SSIS, in the BIDS designer or Visual Studio if you are using SQL Server 2012 we will star with creating a variable of string data type. So, I have created variable strSourceFile. This variable will hold the excel file name and location.

On the Control Flow tab we will start with dragging a ForEach Loop container and an Execute SQL Task inside the container.

We will double click on ForEach Loop task to open the ForEach Loop editor window. We will set the Enumerator as Foreach file enumerator. Next we will select the folder where our excel files exist and we will select Fully Qualified Name from Retrive file name section.

Next we will click on the VariableMapping and select our variable that we defined in SSIS in the above steps.

Next we will double click on Execute SQL Task and open the Execute SQL Task Editor window. We will select ResultSet as None, Connection as our SQL connection manger. We will write EXECUTE StoredprocedureName ? in the SQL Statement. We will select IsQueryStoredProcedure as False.

On the Parameter Mapping section will add one parameter. We will select our variable name that we defined above and keep parameter name and parameter size as 0.

That is all in the SSIS design. Let us move to run our package. I have run the package and it run succefully.

Next I move to see the SQL tables and as expected all records we loaded in the SQL tables.

SQL Table Dept, Emp and Products

So this is how we can load multiple excel files into multiple SQL table. I have shown one way to do this. There could be other ways solving this issue.

I hope the execution concepts are clear. Do let me know if you have any question or comment on this post.

Tuesday, June 4, 2013

SSIS: How to run command Line program and pass arguments to it?

SSIS provides many interesting tasks and components in its kitty to work with. This post is inspired by one of the question asked in a popular SSIS forum. The user wanted to run the command line program and then wanted to write some commands into Command Line prompt window to achieve some specific task.

In an ideal scenario SSIS is not the right choice to develop this type of solution because it is best suited to ETL (Extract, Transform and Load) of data. Nevertheless with SSIS one can achieve this type of task. In this post we will learn how we can run Command Line Program and pass arguments to Command Line window.

Let us consider a scenario where we want to copy a file from one directory to another directory. SSIS has many tasks available which we can use to achieve this but we will see how we can use Command Line Program to copy files.

To copy a file from one directory to another directory using Command Line Program all we have to do is to launch the Command Line Program and write the Copy Command. For example I want to copy xyz.txt as NewXYZ.txt then I have to write following command in Command Prompt window.

With SSIS we will automate this task. We will let SSIS to call the Command Line prompt and we will pass the file name as parameter from SSIS.

We will start with a Batch (.bat) file creation. The objective of this file is that we will write all the commands that we want to execute on the Command Line prompt window. We will pass this file name as argument to command line program.

@echo off
D:
copy %1 %2
exit

The two parameters placeholder in this batch file is defined as %1 and %2. To define the arguments place holder in a batch file we use %1, %2 and up to %9. So we can define 9 arguments in a batch file.

In SSIS we start with defining three variables. The first variable is comd which will hold the batch file name along with attribute /k; which indicates to command line prompt to run the file as it starts. The second and third variable is srcFile and tgtFile which holds to source and destination file name.

In Control Flow tab we have added Execute Process Task.

We double click on the Execute Process Task to launch the Execute Process Task Editor window. In the Executable property we have set the value C:\Windows\System32\cmd.exe; which is the location Command Prompt Window is located in my machine.

Next I clicked on Expression and added expression using three variables defined above.

After setting up the SSIS I run it and it run successfully and copied xyz.txt file in D drive location.

So this is how we can run Command Line Program window and pass arguments to it

Popular Posts

Real Time Web Analytics