What is JSON?

JSON stands for JavaScript Object Notation. It is easy to read, write, understand, parse and generate. It is a collection of key value pairs where key can be any arbitrary string and value can take one of the many forms available from string, number, array, object, boolean and null.

  • String is enclosed in double quotes (“aString”).
  • Number is used as it is (3.14)
  • Objects are enclosed in curly braces ({key:value})
  • Array is composed in square braces ([comma separated values])
  • Boolean can contain either true or false
  • Null is specified as null

Let us declare a JSON object comprising of all the above said value types in variable myObject

var myObject = { 
    "FullName" : "Durgesh Chaudhary" , 
    "Age" : 25 , 
    "WorkedAt" : 
        "Company A" , 
        "Company B" 
    ] , 
    "IsMarried" : false , 
    "SpouseName" : null , 
    "DetailedExperience" : 
            "Company" : "Alpha" , 
            "WorkedInMonths" : 26 , 
            "TechnologyUsed" : ["ASP" , "jQuery"] 
        } ,  
            "Company" : "Beta" , 
            "WorkedInMonths" : 6 , 
            "TechnologyUsed" : ["SQL"] 

In above example we have declared an object named myObject as object (see it is in curly braces) having properties FullName, Age, WorkedAt, IsMarried, SpouseName, DetailedExperience (all keys are enclosed in quotes as they are string) having value of datatype string, number, array, boolean, null and array of objects.

You can create any complex structure using JSON.

What is MongoDB?

MongoDB is an open source, document oriented database written in C++ featuring dynamic schema and classified as a NoSQL database.

Documents (refers to rows in table based schema) are stored in collections (refers to table in table based schema). Some of the features of MongoDB are:

    • Ad hoc queries
    • Indexing
    • Replication
    • Load balancing
    • File storage
    • Aggregation
    • Server-side JavaScript execution
    • Capped collections
    • GridFS
    • Map/Reduce

Durgesh with Pinal Dave

Today we had a session on Big Data delivered by Pinal Dave. It was like my old dream came true, excited like a child, waiting to meet him. I can not express my emotions when I met him. Was at the first set attending his session.

At the end of session rushed to him to get myself photographed with him (jealous no-one else got the photograph :) ), he gave me his visiting card, please do not get jealous if you see his visiting card or this photograph framed at my house.

Installing Ubuntu on VirtualBox

In last article we wrote about Installing Oracle VM VirtualBox and now we install Ubuntu on our virtualbox. If you already know installation of any flavor of Linux/Unix you should be able to install it with ease. There is not any change in steps weather you install OS on physical machine or virtual machine (Yes VirtualBox installations are also known as VM or virtual machines)

RequirementISO image of OS ( we are using ubuntu-12.04.3-server-i386)

Brief Steps :

  • Create a Virtual Machine.
  • Mount ISO image to drive
  • Install Operating System

Create a Virtual Machine (We are going to call it MongoServer)

This slideshow requires JavaScript.

  • Click New icon on the menu bar to begin creation of virtual machine.
  • Give it a name (MongoServer) and select Type as Linux and Version as Ubuntu and click Next.
  • Next it asks for Memory size, you can give it any memory size (RAM) and are only limited by the RAM of your Host machine.
  • Next it is asking for Hard Drive, since we have none so we select Create a virtual hard drive now.
  • It asks for Hard Drive File Type and we leave it to default VDI. You can give fixed size HDD or dynamically allocated. If you give fixed size and space is pre reserved on your Host Machine even if it is not used by Guest OS, while in dynamically allocated VirtualBox expands the HDD file size on demand upto set max HDD size. We select Dynamically allocated to be space efficient.
  • Depending on OS you may give it a size, for Ubuntu we are giving it 8GB which is just sufficient. You can give it more if it does not suit your need. So we are done with Virtual Machine creation.

Next we mount ISO image in a CD ROM.

This slideshow requires JavaScript.

  • Select MongoServer from list and click Settings on the top menu or context menu.
  • It will open settings window for the virtual machine. Go to Storage Tab in the left and select Controller : IDE (Currently Empty) and Chose a virtual CD/DVD disk file after clicking CD icon in right.
  • You need to browse to select ISO image of the operating system you want to install. It is now showing details of the ISO image viz name, Type, size and location. Click OK to exit the window.

Installing Ubuntu in the Virtual Machine.

This slideshow requires JavaScript.

Now we have configured a virtual machine and loaded Ubuntu image as CD ROM we need to continue with the installation.

  • So click Start to start the machine (it is same as powering up a physical machine) We have listed all the steps in image slideshow and you can view corresponding screenshots by browsing. Use Tab or arrows to jump fields and hit enter to click selected button.
  • First of all it asks for Language which is display language for the menu. Select language of your choice (English). Browse to Install Ubuntu Server. Choose installation language (English). Select your location (India). Select Keyboard layout, you can skip it(No). Select Keyboard origin (English (US)). Select Keyboard layout for this machine (English (US))
  • Give Hostname for the machine (needs to be unique : MongoServer). Give your Full Name (Durgesh Chaudhary), Username (durgesh), and password (*********) Encrypt home directory, if multiple users are going to use this machine select Yes else No will also work (No). It shows you the Timezone, if it matches your choose yes (Yes)
  • How you want to partition Disk and set up LVM (Guided : use entire disk and set up LVM), select disk, write changes to disk, type max to format full drive, and finally write the configuration to the disk.
  • Once configuration is saved it asks for Proxy settings (none), automatic updates (disabled), default softwares to install (we selected none).
  • Lastly it asks for installation of GRUB Boot Loader. First you need to know what exactly is boot loader. It is a boot engine which keeps information regarding all the OS installed in the machine and helps you in selecting the machine to load. Boot loader is installed in the first OS what-so-ever you are installing. Later installations simply update it. For linux it is GRUB boot loader and for windows it is windows boot loader, it is one and same. Select Yes to install and continue.
  • After doing all the stuffs it asks for a restart. Once done you can login using your chosen username and password. You can try some basic commands like ls, date, and so on to play.

Installing Oracle Virtualbox

First of all you need Oracle VirtualBox setup, download the same from Official website for your operating system (from here onward it will be called host operating system). We already discussed what is Oracle VirtualBox and why should we install it.

Let us do the installation step by step.
Double click the downloaded installer and it will begin installation. Click Next to begin.

This slideshow requires JavaScript.

  • It is now asking for which component to install. By default all the components are selected, we will leave it as it is and click Next to proceed.
  • Now it is asking weather it should create desktop and quick launch shortcuts. I personally to not require them so I unchecked, you can leave them checked.
  • It makes changes to Network Interfaces as Guest machines may require to access internet and share the network (if you enable). So it gives warning about the same. While installation is in progress you will see a blip in your network and so may require to reconnect with your LAN, WiFi or any kind of network you are using. Click Yes to continue.
  • So we are all set with the installation configuration part, hit Install to begin installation.
  • Oracle VM Virtualbox is installed, click Finish to exit the installation wizard.

When you run Oracle VM VirtualBox, you get an interface as shown in the end.

We are all done with the installation of Oracle VM VirtualBox. Next we will installation Ubuntu on thie VirtualBox to start with.

What is VirtualBox?

The machine from which I am writing this article is SONY VAIO E series VPCEH25EN installed with Windows 7 Home Basic (64bit). You may be wondering why the hell is he telling me all this. I am here to know what is virtualbox and why I require it. Hold on for a while.

So now I want to do some learning on Ubuntu machine or say some other version of windows (for which I have license). How can I do that.

You will say quite easy, make a partition on your hard disk and install it on that partition. But you forgot these questions.

  • I require these machine for RnD purpose and only for some days.
  • I require a lot of them which will require a lot of partitions.
  • And above all I can work on one of them at a time.

But virtualbox help you by overriding all the said problems. You can install multiple OS on a single Host machine only limited by your RAM and HDD space. You can run individual Guest as and when you require on demand and they all can run at the same time and talk with each other as they are in a network.

I have installed multiple ubuntu server installations to ease me in development and maintaining separations between PHP dev machine, Java dev machine, mongoDB server and so on. When I am doing PHP stuff I boot php machine and start coding and so on.

So my host machine is not overloaded at boot time. There are many applications like Microsoft AppFabric, VMWare and so on, but I like and trust VirtualBox the more.

Connect SQL Server in .Net using C#

In this post we are going to create a connection with Microsoft SQL Server using .Net Framework and we would be using C# as our language.

In order to perform SQL related tasks we need to use SqlClient under Data therefore we would add following line in the code window of each form where we will be performing SQL related tasks.

using System.Data.SqlClient;

Next we need to create a connection which we will be using for dealing with SQL Server. There are many methods to do that but what we will be doing is we will create a static connection so that we can use that connection at all the places and any Server related changes can be done at only one place. Other option is to create a connection anywhere as and when required but it adds a problem when you need to modify the server properties.

For windows application we will be doing this in Program.cs file and for web application we will be doing this by creating a new class.

Here we are demonstrating the same for windows application.

In Program.cs file after writing following line at the top section

using System.Data.SqlClient;
Create a static connection variable as follows
public static SqlConnection Conn = new SqlConnection("data source=localhost; integrated security=sspi;initial catalog=database_name");
In the above statement we are creating a static SqlConnection object to hold the connection to Server. We are passing a single argument to the constructor with some properties values as explained below:-

data source=localhost;

This defines the data source to be used. Generally we provide ‘localhost’ or ‘.’ . We can also give the name of the server which can be found in the Server Manager

integrated security=sspi;

Above property tells about the method to be used for authentication. ‘sspi’ tells not to pass the values and go with the windows authentication. It is more secured as username and password is not stored here for creating a connection else we need to provide the same in connection parameter.

initial catalog=database_name;

We need to pass the name of the database with which we want to create a connection, in this argument. These three property values create a connection with the database server.