Monday, December 12, 2011

Opening Multiple Instance of VISIO 2010

I had a strange issue with Visio 2010, unable to open multiple instance of Visio and its hard sometime to switch back between the diagrams. 

I found the fix for the issue and posting the solution here for others to follow
  1. Open your registry (Start >> Run>> regedit
  2. Open the following registry path "HKEY_CURRENT_USER\Software\Microsoft\Office\14.0\Visio\Application\"
  3. Add a new Key>>  choose Binary Key and give it a name called "SingleInstanceFileOpen" 
  4. leave the default value "0 0 0".
  5. close the regedit window as well as all instance of Visio 

Open different instance of Visio and you should be good to go now...

Not sure why Microsoft did this injustice to Visio alone



Thursday, December 1, 2011

Mongo DB - Schema less database - Series 2



Overview:  In this section we'll see how to start the Mongo DB engine, create database and basic CRUD operations


Starting Mongo DB

The two "most important" applications are the mongo and mongod
applications. 

The mongo application allows you to use the database shell; this shell enables you to
accomplish practically anything you'd want to do with MongoDB.

The mongod application starts the service or daemon, as it's also called. There are also many flags you can set when launching the MongoDB applications


executing the mongod.exe from command prompt (Tips: Set the path in the environment variables, so that you don't need to navigate to the actual folders)



There is a nice comparison between Mongo DB and Oracle & My SQL in Mongo web site, a helpful tip for newbies http://www.mongodb.org/display/DOCS/SQL+to+Mongo+Mapping+Chart


I've listed down a key comparison between Mongo and other RDBMS
RDBMS
MONGO
Database
Database
Tables
Collections
Rows
Documents

In MongoDB, a document is an item that contains the actual data, comparable to a row in SQL.


Important Note:
Mongo DB is case-sensitive
$ symbol is reserved for many built-in functions


 
DATATYPES

String
Text values
Integer (32b and 64b)
Numerical values
Boolean
True or False
Double
Floating point values
Min/Max
Comparing values against Lowest  and Highest BSON elements
Arrays
Store array of values
Timestamp
Store Time stamp
Object
Object  type values
Null
Null values
Date*
Current Date
ObjectID*
Documents unique ID
Binary Data*
Binary format data
JavaScript Code*
Store JavaScript code
Regex*
Regular Expression type
*denotes BSON data types

 CRUD Operations

Before i dive in to CRUD operation with example, there are few important commands to do the basic operations like Listing all databases, connecteing to database,  listing all documents, etc...

One interesting command to remember is : 'Show'  this is almost a replacement for 'Select * from'


use
To switch to a db library
show dbs
To view available databases and collections
show collections
To view all available collections for your current database
system.indexes
All the indexed are stored here
db..renameCollection("Target DB")
Renaming a Collection
db..distinct("xxxxx")
Getting distinct data collection

Monday, November 14, 2011

Mongo DB - schema less database - Series 1

Overview:  

I'm leveraging the new schema less database called Mongo DB and thought write a blog and share my experiences/knowledge to the community.  I'm creating a series of post to explaining  from  overview to install to implementation using both Python as well as from C#.

In this post I'm going to give you an overview and explain installation option and some silent feature.

Series 1 : Overview, Install and key feature

What is Mango DB?

A MongoDB database is non-relational and schema less database and its designed based on document storage concept. This means that a MongoDB database isn't bound to any predefined rows, columns, constraints,  data types, etc... the way that traditional relational databases are (Oracle, SQL-Server, DB2, MYSQL, etc…).

The philosophy in which the MongoDB  was designed is "one size does not fit all".  What is this means in reality?  It is simple , lets say we have a situation where we need to store different data attributes based on a type of document (RDBMS: Rows).  

example:

We have a table called Audit and based on the audit type one row can have a type that is defined as a string and another type can be Date Time and another one may have more than one value (a collection of data), this is impossible in RDBMS from a single table.  We need to normalize  and every time there is a need for another type of collection, we may need to build another table, in contrast MongoDB or any other Document DB, it is simple since they are based on the key value pair.  The key is a string and the value in it can be anything.  That’s the beauty of this DB.  Is it a replacement for Relational Database?  The answer is a big 'No', it depends on the need or complexity.


How does I query the data? 
It is really simple, since MongoDB is all about  document Object type,  JSON  is the ideal choices. 

JSON  (Java Script Object Notation)  is a lightweight data-interchange format, which is completely independent from programming languages.  JSON primarily works with two different structured data:
  • A collection of name/value pairs.
  • An ordered list of values.


To learn more about JSON, visit : http://www.json.org/

BSON (Binary Java Script Object Notation):
MongoDB doesn't actually use JSON to store the data; rather, it uses an open data format developed by the MongoDB team called BSON.  BSON makes MongoDB even faster by making it much easier for a computer to process and search documents. BSON also adds a couple of features that aren't available in standard JSON, including the ability to add types for handling binary data.

Does this mean learning a new Query Language?  No, if you are familiar with JSON, it is straightforward,  BSON is built on top of JSON and supports current JSON query on top of few additional features that are specific to binary data.

How does the MongoDB actually stores data?  It is simple as a document with a  keys and values, it generated an uniquely identifier key and assigns to each document, unless we specify a unique key field.  Think this is similar to RowID in Oracle or  ROW_NUMBER()  in SQL server.


Installing MongoDB under Windows

Prerequisites

Before we can start the MongoDB service, we need to create a data directory for MongoDB to
store its files in. The following folders  are configured to use by default by MongoDB

C:\data\db directory

But, they are not created by default, so we need to create them manually; otherwise, MongoDB will fail to run and throw an error message.

Once the folders are created set the read, write, and directory creation permissions to function properly.

Note: If you wish to use a directory other than the default , then we need to  tell MongoDB to look at the custom  directory by using the "dbpath" flag when executing the service.

Download & Install

Select the latest windows build (2.0.1) of MongoDB from http://www.mongodb.org/downloads
After you download the Zip file, extract the zip file and drop it in a location you prefer to,  I like all the software's to be located under C:\Program files directory

C:\Program Files\mongodb-win32-i386-2.0.1

Once you extracted the zip file and moved to preferred location, you'll see the following directory structure

 
Under the bin directory where you'll see bunch of executable  (these are the only executable' s we need to run the entire database engine)




The main executable are listed below

mongod.exe
core database server
mongo.exe
Database shell
mongorestore.exe
Utility to import /restore
mongodump.exe
Utility to export/backup
mongos.exe 
auto-sharding process


Installing additional drivers for application integration

Currently, MongoDB includes drivers for the following programming languages and can be accessible from


As I mentioned earlier in the blog , I'm trying to leverage my development using C# as well as Python, I'm showing here the download and install instructions for the same technologies:


.Net Driver (C#): is very straightforward:  Just download the Microsoft installer version (.msi file) from  http://github.com/mongodb/mongo-csharp-driver/downloads and run  the msi.  This will install the required driver file (C#)  and also the help files


Python Driver: Download pymongo-2.0.1.tar.gz from  http://pypi.python.org/pypi/pymongo/#downloads and install using the 'easy_install' utility, which is available under scripts directory




To confirm Python MongoDB driver is working in python run the following command  from python shell (command line) and should expect no result

import pymongo




in the next  Series 2, we'll see how to start creating database, documents and accessing the same using JSON (BSON object).
 

Thursday, March 3, 2011

Custom Description for Enumerator

Here I would like to show how we can create custom description with enum types. Typically enum types are a single word without a space, lets assume we have country enum types, but we also like to use the enum to show a fully qualified country name rather an abbreviated one: How is this possible? by defining Description attribute to enum type and by simply using reflector to read the description. I have listed down a code snippet to show how to define and consume.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;
using System.Reflection;
namespace EnumCustomDescription
{
public class MyEnum
{
///
/// Adding Custom Description attribute to enumerator type helps to define more descriptive enum values rather than a single word or abbriviated value
/// use reflector class to retun the description instead of the actual enum value.
///

public enum enumCountry
{
[Description("United State of America")]
USA,
[Description("Australia")]
AUS,
[Description("India")]
IND,
[Description("South Africa")]
SA,
[Description("United Arab Emites")]
UAE,
[Description("United Kingdon")]
UK
}
}

public class GetDescription
{
///
/// GetEnumeratorDescription method will return the value defined in the Enum description, this uses the reflector
/// to read the description from the enum class
///

/// enumerator
/// description of the custom attribute
public static string GetEnumeratorDescription(Enum value)
{
FieldInfo _fieldInfo = value.GetType().GetField(value.ToString());
DescriptionAttribute[] _attribute = (DescriptionAttribute[])_fieldInfo.GetCustomAttributes(typeof(DescriptionAttribute), false); ;
if (_attribute.Length > 0) { return _attribute[0].Description.ToString(); }
return value.ToString();
}

}
}