Archive for the ‘ASP.NET’ Category

Software Requirements

  1. MySQL DB with Work Bench
  2. MySql Connector for .NET
    Download the binary and install to your machine where you need to run your application.
  3. .NET Platform / Visual Studio
    You may download and install the .NET framework of your required version 1.1/2/3.5 or 4.
    This article supports all the above mentioned versions.

MySql Database Creation and Table Creation
I assume that you can create MySql Database and Tables I proceed to the C# Programming part

Web.config File
The following is a simple connection string statement I use in my development practice. You may also ignore Web.config and write the connection string inline on the code page. But it is not recommended as it is vulnerable to disclose your database credentials (Database Username and Password) in the code page. Say you may have more than one developers working on the project and you many not want to share the database credentials with them, this practice will help you the most. Apart from this the content in the web.config file is more secured than content in other pages by the ASP.NET architecture.


<add  name=”<give some name to call this connection string>”
connectionstring=”server=ip address or name>
initial catalog=<database name>
uid=<database username=””>;
pwd=<database password>”


<add  name=”MyConnection1″
initial catalog=mysampledb;

Here I use ASP.NET and C# to explain the database programming with MySql. I assume that you have basic knowledge of ASP.NET and C# programming.

Go to the code behind and proceed with the following code.

  1. Incluse the usings.

    using MySql.Data.MySqlClient;

  2. Declare the private variables inside the main class (pls not the class not the main function)

    MySqlConnection con = new MySqlConnection(ConfigurationManager.ConnectionStrings[

    MySqlCommand cmd;
    MySqlDataReader dr;
    DataSet ds = new DataSet();

  3. Opening Database Connection

    if (con.State == ConnectionState.Closed)

  4. Adding Data to the Database

    string qry = “INSERT INTO sample_table(first_name, last_name)”;
    cmd = new MySqlCommand(qry, con);

Introduction to C# / ASP.NET with C#

ASP.NET is a Microsoft technology for web applications. ASP stands for Active Server Pages. As the name specifies the pages are programs that are stored and executed on the server. When a call is made to the page the page gets compiled (if not already compiled) and returned to the client browser as a file in HTML and JavaScript combination. The .NET platform is a proven Microsoft technology for applications. ASP.NET is limited to Windows platform. We will discuss more about the ASP.NET and C# in a separate article soon.

Introduction to MySql Database
MySql is an opensource database backed by Oracle Corporation. It is a powerful and efficient database that you can rely on it for your enterprise needs. Most companies prefer MySql for their data storage needs and high transaction processing. MySql is reliable and programmer friendly too. It has a large user base and strong community to support. However, the PHP & MySql combination is the best pair on internet! It is not that C# doesn’t go well with MySql but the opensource PHP beat the C# or any other language on Internet. Let us not worry about that! We have enough articles and resources for C# integration and programming with MySql and abundant help content for MySql. We will discuss more about the MySql in a separate article soon.

Source : Arun’s Blog

How to use ILMerge?

Posted: 28/12/2013 in ASP.NET

IL Merge is a technique and a research product from Microsoft, to merge multiple DLLs and EXEs (.NET Assemblies) together to form a merged file (exe or dll). This way no separate DLL file is required.
Follow the below steps for merging an exe and dll associated with the project.

Installing ILMerge

ILMerge is not distributed with the .NET framework and so must be obtained and installed separately. The installation file can be downloaded free-of-charge from the ILMerge download page of the Microsoft web site. Once downloaded, simply double-click the file to begin the installation process and follow the instructions provided.

Download and install the ILMerge utility from Microsoft Website.
Step 1: Download ILMerge utility and install it in your machine
Step 2: Compile and Publish your Project to a folder (eg: C:\Publish\)
Step 3: Use the ilmerge command to merge the exe and dll files and output single exe file
ILMerge Command
Syntax (Simple*): ilmerge /out: /target:<dll|exe|winexe>
*For complete set of options and syntax refer ILMerge Documentation
C:\Program Files\Microsoft\ILMerge>ilmerge C:\Publish\MyProgram.exe C:\Publish\MyLibrary.dll /out:C:\Publish\MyWinApp.exe /target:winexe /ndebug

Source : Arun’s Blog

1) Flash CS5.5 – Has become a very good solution with the Flash iPhone Packager.  The packager for iOS allows you to compile apps on the windows platform.  If you’ve been using flash you can rejoice in Apple’s latest policy, it performs ok, but don’t expect highest performance games, and Papervision to run in here.  No mac required.  Something that has been asked is if it is possible to create flash iOS apps in an evironment other than the official Adobe one.. absolutely, you can compile with the Flex compiler, and package your apps for iPhone as long as you follow the asme guidelines.

2) Airplay SDK – The airplay SDK allows you to create games, and sign your app on Windows PC’s.  A great solution for both 2D and 3D games and apps because of the free offer made to indie developers.

Both these solutions can compile to code that is native to the iPhone right on your windows PC and many apps available in the app store have been created using them.

3) Unity 3D – Game development engine and editor that utilizes Boo and C# and the editor works on both Windows and Mac.

4) Stonetrip S3D – Game develop engine and editor utilizing LUA, the editor runs within Windows.

These game engines allow you to develop your apps on Windows, but you’ll need a Mac to test/compile

3) Appcelerator Titanium – This is a good solution, and has a very popular and vibrant community.  Apps are limited in performance because while they can be compiled as native apps and sent into the app store they are html/javascript based.

4) Genuitec MobiOne – This is an interface designer that uses the Phonegap framework to deliver native functionality.  It only runs on windows.  HTML/Javascript based.

These solutions allow you to create apps using web technologies (HTML/CSS/Javascript) and then run them through an Objective-C framework that responds to actions within a UIWebView, thus allowing you to access native functionality on the iPhone.  These frameworks are free.  You will need a mac for native testing/compilation.

5) Dragonfire SDK – An interesting option that allows you to develop apps using their SDK on windows.  Then you send them your uncompiled source which they compile and you download the compiled iOS application file.  You upload your code for compiliation on their server (as long as you have the Ultimate edition).  I like the syntax and it’s pretty popular so I’ll mention it.  It is a good wrapper with a nice simulator on Windows.

There are a couple of other solutions that were either in testing, required payment without any form of trial (or in some cases even screenshots), or just aren’t out yet many of them seemingly lesser versions of the Dragonfire SDK that enable iPhone development on Windows by compiling your source code for you.. Airplay SDK is probably the most advanced “iOS SDK on Windows” available free at this stage.

iPhone Development On Windows Now A Real Possibility

My suggestion is that you are really set on windows iPhone development and rdon’t even want to buy a Mac Mini is that you create your app using an html/javascript solution such as Phonegap/Appcelerator or the Airplay SDK and then find someone with a Mac and hit them up to do the submission for you.  Airplay SDK is the only free solution for creating high performance iPhone/iPad games using Windows.  You can use the Flash builder, but there are currently some performance limitations – a new edition is coming out soon.

Update: Airplay SDK has unfortunately been renamed Marmalade SDK and no longer provides a free solution for indy developers.

Best of luck, if you know of any other alternatives that enable iPhone development on Windows or if any of the info above has changed that enable iPhone Development on Windows

Most of us prefer creating bootable USB drives to install Windows or other OS. Use of a USB drive to install an OS saves time and you don’t need to waste your CD/DVD. There are many freeware available to create bootable USB drives which are mentioned in following topic:

Collection of Freeware to Create Bootable USB Drive to Install Windows and Linux

Although creation of bootable USB drive is an easy process but it requires some time. Sometimes you need to select files and other settings to create a bootable USB drive. Wouldn’t it be great if you could create a backup image of your bootable USB drive and whenever you need it again, just restore the backup image again?

Also imagine another scenario. Recently Microsoft released Windows 8 RTM to public and you can purchase and download your copy using Upgrade Assistant. This tool downloads the setup files and then allows you to create a bootable USB drive to install Windows 8 in your system. Suppose you created the USB drive but you don’t want to install Windows 8 immediately. After some time you need the USB drive for some other purpose. Now you can’t format the drive because it’ll delete Windows 8 setup files. So your USB drive will be useless for you until you install Windows 8 using it. And what if you format the drive after installing Windows 8 and in future you need to install Windows 8 again? How will you install it? Creating a backup image of Windows 8 bootable USB drive will save you again.

That’s why today in this topic, we are going to share a free software which allows you to create a backup image of USB drives.

USB Image Tool” is a freeware for Windows which can create images of your USB flash drives as well as MP3 players and also allows you to restore them later.

Features List:

  • Creates backup image files of USB flash drives
  • Restores backup images to USB flash drives
  • Supports compressed image file format
  • Shows USB device information
  • Manages favorite USB images
  • Also provides command line utility


This free tool can be used to create backup images of almost all types of USB devices such as flash drives, card readers, digicams, cell phones and mobile music players.

Its a portable tool so you don’t need to install it. Just download and run the program. Using the program is very easy. You can create the backup or restore the backup in a few clicks.

It can be used in Windows XP, Vista, Windows 7 and Windows 8. Both 32-bit and 64-bit editions are supported.

You can download it using following link:

Download USB Image Tool

Hadoop 2.0 goes beyond MapReduce to create a general framework for distributed data-processing applications


The new Hadoop is nothing less than the Apache Foundation’s attempt to create a whole new general framework for the way big data can be stored, mined, and processed.

It ought to not only further stimulate the way apps are written for Hadoop, but also allow for the creation of entirely new data-crunching methodologies within Hadoop that simply weren’t possible because of its earlier architectural limitations. In short, it’s good stuff.

What’s been holding Hadoop back all this time? More important, where’s it going from here?

Various criticisms of Hadoop have revolved around its scaling limitations, but the biggest constraint on scale has been its job handling. All jobs in Hadoop are run as batch processes through a single daemon called JobTracker, which creates a scalability and processing-speed bottleneck.

With Hadoop 2, the JobTracker approach has been scrapped. Instead, Hadoop uses an entirely new job-processing framework built using two daemons: ResourceManager, which governs all jobs in the system, and NodeManager, which runs on each Hadoop node and keeps the ResourceManager informed about what’s happening on that node. (Each running application also has its own governor, ApplicationMaster.)

This setup is so unlike the previous MapReduce that Apache gave it an entirely new name: YARN, or Yet Another Resource Negotiator, with the new MapReduce running as one of many possible components for it. In fact, Apache claims that any distributed application can run on YARN, albeit with some porting. To that end, Apache’s maintained a list of YARN-compatible applications, such as the social-graph analysis system Apache Giraph (which Facebook uses). More are on the way from other parties, too.

As radical as this approach is, Apache wisely decided not to break backward compatibility, so MapReduce 2 still has the same APIs as its predecessor. Existing jobs just need a recompile to work properly.

It’s also hardly coincidence that YARN makes Hadoop far more cross-compatible with other Apache projects for massaging big data. Use one, and it becomes far easier to use the rest. Such a rising tide for Hadoop would help lift all of Apache’s related boats.

The biggest win of all here is how MapReduce itself becomes just one possible way of many to mine data through Hadoop. Apache’s own Spark, another candidate for porting to YARN, might be better suited to some kinds of work than MapReduce, so Hadoop 2 gives you more flexibility to choose the engine that’s the best fit.

The two big Hadoop vendors, Cloudera and Hortonworks, both have their own discussions of how YARN is crucial stuff, even if they approach Hadoop from markedly different directions. Cloudera’s Impala offers the ability to run low-latency SQL queries against HDFS-stored data, which makes them best suited to live analytics; Hortonworks has chosen to go with Apache’s native Hive technology, which is best for data warehouse operations (like long-running queries with lots of join-type operations).

Porting apps to YARN isn’t a trivial effort, though, so the payoff involved in reworking Hadoop this radically will be strongly based on how much gets deployed within the new framework. But the fact that both Cloudera and Hortonworks are solidly behind Hadoop 2 and haven’t forked the product — or stuck with its earlier iterations — is major evidence Hadoop 2 isn’t just smoke or mirrors. Or tangled yarn.

Encoding Vs Encryption

Posted: 12/10/2013 in ASP.NET

 Encoding and Encryption are somewhat similar concept but these are different in purpose. Encoding means transforming data to another format with schemes that are publicly available like base64 encoding scheme. Later on, anyone can decode to convert it back to original format. Purpose of encoding might be compressing to save memory or confirming the transfer of data over a channel etc. In case of Encryption, transformation of data to another format is done with the purpose of security, so that not everyone can read data except the ones having decryption key/password etc. Encryption id done using some specific key or password.

Online Quiz Coding

Posted: 08/09/2013 in ASP.NET


The idea to write an online quiz came up when I was looking for an XML tutorial. I visited and found not only the tutorial I was looking for, but more interestingly was an online quiz. I took the 20-questions quiz once, and hey! I felt great about it. I wonder why there are just few web sites offering online quiz like that.

A quiz is a great way to test your knowledge. An online quiz is a great addition to your web site that could keep your visitors glued for a few more minutes.

Download the demo project and try it. It is a 10-question quiz to challenge your knowledge about Australian geography. Don’t worry! All data is kept in a clear, human-readable XML document, so you could easily peek for answers.

The Script Explained

I will not go through a very detail discussion about the script, but rather highlight several areas in the script. Once you get the whole idea about the script, then it is easy to modify or extend the script to suit your requirements.

Recursive Script

There is only one aspx script to do various tasks in the online quiz. It is a recursive script: a script that ‘calls’ itself over and over again until a certain condition is reached. Precisely, the script does not call itself, but posts form data to itself. This process is known as post back.

As the script posts back to itself continuously over the duration of the quiz, we could say that it has many states. The first state is to initialize several essential variables, count the total question, and record the quiz start time. Then, in the first and each following state, the script displays a multiple choice question to challenge user (see the snapshot above). A user answering the question will trigger onClick event, forcing a post-back, and move the script to the next state. In the next state, the script will run a subroutine associated with the event to check the answer and display the next multiple question. The recursive flow repeats again and again, until the last question is processed, where at this point a result is displayed.

The following activity diagram represents the recursive flow of the online quiz script.

Maintaining State

The online quiz script needs to maintain state of its variables. There are a bunch of alternatives to do so. The most advanced way is to use the session object, and the conventional way is to use hidden inputs or a QueryString. ASP.NET introduces another alternative called ‘state bag’. Unlike the session object, state bag is not persisted over the whole user session, but is brought forward from one page to another page just like hidden inputs and querystring. However, it is superior to hidden inputs and QueryStrings, since it can accept more data types and the content has been encoded into a single string and therefore is not easy to tamper with.

Storing value into state bag:

 Collapse | Copy Code
ViewState("TotalQuestion") = intTotalQuestion

Getting value from state bag:

 Collapse | Copy Code
intTotalQuestion = ViewState("TotalQuestion")

The following is a list of variables to be kept in the state bag:

Variable Name State Bag Name Data Type Comments
intTotalQuestion TotalQuestion int Keeps the total question in the quiz. The value is populated in the first state of the quiz and remains constants over the duration of quiz.
intScore Score int Keeps the number of correct answer.
intQuestionNo QuestionNo int Holds the last question number the user attempted.
arrAnswerHistory AnswerHistory arraylist of int Records answers in the quiz. It will record 0 (zero) if the answer is correct, otherwise record the selectedindex of the radio buttons.
(none) CorrectAnswer int Holds the correct answer of previous question. It is made available in the next state when the answer is checked for correctness.
(none) StartTime date Holds the start time of the quiz. It is used to calculate the time spent in the quiz.


XML Data

Data for the online quiz is kept in an XML document named quiz.xml, which is validated using an XML schema namedquiz.xsd. A valid XML document consists of a root element called quiz, which has at least one element called mchoice(short for multiple-choice). Each mchoice element has one question child element, and two or more answer child elements. The answer element may have the correct attribute with possible value of either yes or no. In fact, you should supply the correct attribute with a value of yes to one of the answers in the same mchoice, otherwise there will be no correct answer for the question.


 Collapse | Copy Code
<?xml version="1.0" encoding="UTF-8"?>
<quiz xmlns:xsi=""
    <question>What is the capital city of Australia ?</question>
    <answer correct="yes">Canberra</answer>
    <answer>Gold Coast</answer>
    <question>Which city has an extensive tram network?</question>
    <answer correct="yes">Melbourne</answer>

It is possible to insert HTML tags within the XML data, therefore the quiz may contain decorated texts, images, links, etc. instead of plain text. Just make sure to enclose the HTML tags with CDATA block, so the XML document is still valid. Look at the following example:

 Collapse | Copy Code
    <question><![CDATA[<span>Which of the following is <u>NOT</u> 
Australian native animals?]]></span></question>
    <answer correct="yes">Penguin</answer>



 Collapse | Copy Code
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs=""
elementFormDefault="qualified" attributeFormDefault="unqualified">
  <xs:element name="quiz">
        <xs:element name="mchoice" maxOccurs="unbounded">
              <xs:element name="question" type="xs:string"/>
              <xs:element name="answer" minOccurs="2" maxOccurs="unbounded">
                    <xs:extension base="xs:string">
                      <xs:attribute name="correct" use="optional">
                          <xs:restriction base="xs:string">
                            <xs:enumeration value="yes"/>
                            <xs:enumeration value="no"/>

The online quiz script does not validate the XML document against the XML Schema for several reasons. First, it is a resource intensive process, forcing XMLTextReader to go through each element and attribute in the XML document. Second, we need to validate the XML document just once after it has been updated, instead of every time we load the file. To validate the XML document, you could write a separate aspx script or use a third-party tool and run them manually every after you finish updating the XML document.

XML Document Object Model

XML Document Object Model (DOM) is a tree-like structure that represents every node of an XML document based on the hierarchical relationship with its parent nodes and child nodes. The DOM allows us to navigate and manipulate XML document in more logical way.

To build an XML DOM, we use the XMLDocument class. The XMLDocument class itself extends the XMLNode class, therefore many of its properties and methods are inherited from XMLNode. While XMLNode’s methods and properties apply to a specific node in an XML document, methods and properties of XMLDocument apply to the whole XML document.

The following code create an instance of XMLDocument and build XML DOM from quiz.xml:

 Collapse | Copy Code
Dim xDoc as XMLDocument = New XMLDocument()

Addressing a specific node in the XML DOM is a bit tricky. We should navigate our ‘pointer’ through the DOM starting from its root node. The following code demonstrates how to address the first question of the first multiple choice:

 Collapse | Copy Code
Dim xNode as XMLNode

'Goto the first/base element in the file, which is <?xml ?>
xNode = xDoc.DocumentElement

'Goto the next sibling of current node, which is <quiz>
xNode = xNode.NextSibling

'Goto the first child of current node, which is <mchoice>
xNode = xNode.FirstChild

'Goto the first child of current node, which is <quiz>
xNode = xNode.FirstChild

'Print the content of current node
Response.Write("The question is: " & xNode.InnerHtml)

It is definitely a tedious task, particularly if you want to address nodes located at a very low level in the hierarchy. Luckily, we can utilize the XPath language to more directly address a specific node or a group of nodes. If you are unfamiliar with XPath, it will be briefly explained in the next section.

The SelectNodes method of the XMLNode and XMLDocument class’ accepts an XPath string and returns a collection of XMLNode objects, called XMLNodeList. Another method, SelectSingleNode, does just the same thing but return only a single XMLNode object.

 Collapse | Copy Code
'Using SelectNodes to address all answers of the first multiple choice
Dim xNodeList As XMLNodeList
Dim i as Integer
xNodeList = xDoc.SelectNodes("/quiz/mchoice[1]/answer")
For i = 0 to xNodeList.Count-1
  Response.Write("<p>" & xNodeList.Item(i).InnerHtml)

'Using SelectSingleNode to select the first question of the first multiple choice
Dim xNode as XMLNode
xNode = xDoc.SelectSingleNode("/quiz/mchoice[1]/question")
Response.Write("The question is: " & xNode.InnerHtml)


XPath is a language to address specific nodes in an XML document. It could address a single node or a group of nodes by describing its hierarchy relationship in a string, therefore it is often called an XPath string. If you are familiar with file path or URL, then the concept of XPath is nothing new.

Read the XPath string from left to right and you will be able to figure out the node it is addressing. Except for several conditions and functions, XPath is actually easy to use. The following table demonstrates some usage of XPath againstquiz.xml:

XPath String Result
/quiz Select the root node of XML including all elements it contains.
/quiz/mchoice Select all mchoice child elements of the quiz
/quiz/mchoice[1] Select the first mchoice (multiple choice) child element of the quiz
/quiz/mchoice[1]/question Select all questions of the first multiple choice of the quiz
/quiz/mchoice[1]/answer[4] Select the fourth answer of the first multiple choice of the quiz
/quiz/mchoice[1]/answer[4]/@correct Select ‘correct’ attribute of the fourth answer of the first multiple choice of the quiz

XPath contains a lot more surprises. If you are interested enough to explore more, check out the XPath Tutorial at W3CSchools.


This article presented an online quiz as a tool to add interactivity to your web site. It also explored several topics like recursive scripts, navigating and manipulating XML documents using the XML DOM, a glimpse of the XPath language, and a brief discussion about state maintenance.


Enrico Elizar Samuel

Web Developer
Singapore Singapore