Skip to content

Jagdeep Mankotia


Take Database backup in .bak format

= ‘c:\Backupmydatabase.bak’

Restore database from .bak

FROM DISK = ‘C:\Backupmydatabase.bak’

Some time you may face blow problem:
Error 3154: The backup set holds a backup of a database other than the existing database.

Solution is very simple and not as difficult as he was thinking. He was trying to restore the database on another existing active database.

1) Use WITH REPLACE while using the RESTORE command. View Example
2) Delete the older database which is conflicting and restore again using RESTORE command.
I understand my solution is little different than BOL but I use it to fix my database issue successfully.
3) Sample Example :

FROM DISK = ‘C:\Backupmydatabase.bak’


Method overloading means having two or more methods with the same name but different signatures in the same scope. These two methods may exist in the same class or anoter one in base class and another in derived class.

class Person


private String firstName;

private String lastName;



this.firstName = “”;

this.lastName = “”;


Person(String FirstName)


this.firstName = FirstName;

this.lastName = “”;


Person(String FirstName, String LastName)


this.firstName = FirstName;

this.lastName = LastName;



Calling Overloaded Methods.

Person(); // as a constructor and call method without parameter

Person(userFirstName); // as a constructor and call method with one parameter(like User’s first Name)

Person(userFirstName,userLastName); // as a constructor and call method with one parameter(like User’s first Name)

When to use Method Overloading?

Generally, you should consider overloading a method when you have required same reason that take different signatures, but conceptually do the same thing.


Method overriding means having a different implementation of the same method in the inherited class. These two methods would have the same signature, but different implementation. One of these would exist in the base class and another in the derived class. These cannot exist in the same class.

Overriding methods

Overriding method definitions

In a derived class, if you include a method definition that has the same name and exactly the same number and types of parameters as a method already defined in the base class, this new definition replaces the old definition of the method.


A subclass inherits methods from a superclass. Sometimes, it is necessary for the subclass to modify the methods defined in the superclass. This is referred to as method overriding. The following example demonstrates method overriding.

Step 1

In this example we will define a base class called Circle

class Circle

//declaring the instance variable

protected double radius;

public Circle(double radius)
this.radius = radius;

// other method definitions here

public double getArea()
return Math.PI*radius*radius;

}//this method returns the area of the circle

}// end of class circle

When the getArea method is invoked from an instance of the Circle class, the method returns the area of the circle.

Step 2

The next step is to define a subclass to override the getArea() method in the Circle class. The derived class will be the Cylinder class. The getArea() method in the Circle class computes the area of a circle, while the getArea method in the Cylinder class computes the surface area of a cylinder.

The Cylinder class is defined below.

class Cylinder extends Circle

//declaring the instance variable

protected double length;

public Cylinder(double radius, double length)
this.length = length;

// other method definitions here

public double getArea()
// method overriden here
return 2*super.getArea()+2*Math.PI*radius*length;
}//this method returns the cylinder surface area

}// end of class Cylinder

When the overriden method (getArea) is invoked for an object of the Cylinder class, the new definition of the method is called and not the old definition from the superclass(Circle).

Example code

This is the code to instantiate the above two classes

Circle myCircle;
myCircle = new Circle(1.20);
Cylinder myCylinder;
myCylinder = new Cylinder(1.20,2.50);


Understanding C# Access Modifiers

Information hiding is essential in object oriented as well as in modular programming. C# provides the access modifiers private, internal, public, protected and protected internal to give a programmer fine grained control over the visibility of a member in a specific context. Those contexts are namespace, class, struct, interface and enum. A member would be e.g. a field, an event, a delegate, property or method. But, as Marc’s table shows, this does not really matter. A member’s context alone determines if a modifier can be applied at all (□), and which modifier is the default (■).












protected internal

*) Because members of interface and enum are always public by default, the modifier must not be applied in those contexts.

The individual access modifiers are defined in the C# Language Specification as


Access limited to the containing type


Access limited to this program


Access not limited


Access limited to the containing class or types derived from the containing class

protected internal

Access limited to this program or types derived from the containing class

Now I will help you how to bind DropDownList with the dynamic Years.

2007 … and so on


int year = DateTime.Now.Year;
int lastyear = (year – 50); // Subtract 50 from current Year

ArrayList ds = new ArrayList();
for (int i = year; i >= lastyear; i–)
ddlLevyYear.DataSource = ds;

Happy Coding.

== Jagdeep Mankotia



AddSubdomain to your website in IIS programmatically.

Belowprogram/Code(C #) help you to create a subdomain to a specificwebsite. It adds a host header to a website in IIS. This involveschanging the ServerBindings property. There is no Append method thatcan be used to append a new serverbinding to this property, so whatneeds to be done is read the entire property and then add it backagain, together with the new data. This is what is done in the codebelow. What you need is to create a class andpass the parameter to that class. The subdomain will createautomatically.


publicclass HostHeader


       //Example: "SubdoaminName", 677458785,,domain name

       public static void AddHostHeader(string hostHeadervalue, string websiteID, string IPAddress, string website)


          //Websiteit is some integer value. Find it form IIS.

          DirectoryEntry site = new DirectoryEntry("IIS://localhost/w3svc/"+ websiteID);



              //Geteverything currently in the serverbindings propery.

              PropertyValueCollection serverBindings = site.Properties["ServerBindings"];

              //Addnew subdomain name TCP port: 80

              serverBindings.Add(IPAddress+ ":80:"+ hostHeadervalue + "."+ website);


              //Createan object array and copy the content to this array

              Object[]newList = new Object[serverBindings.Count];


              //Writeto metabase

              site.Properties["ServerBindings"].Value= newList;

              //Committhe changes









Above code should be add in the class file.

Do not forget to Import "System.DirectoryServices;" name space.



I have explained you how to add a sub domain to your website. But after adding sub domain you main face some problem like it will not work when you open you website from other computer.

If you face this kind of problem, then I have solution for the same. There are two solutions I am going to explain both the solutions.

Method 1. You needs to add identity impersonate to you web configuration file. Identity Impersonate stores the username and password of the user. This user must have the rights in you IIS. This may be your server login administrator or you can create you own user with administrator rights.

Code to


<identity impersonate="true" userName="AdminUserName" password="password" />

Write above code in the webconfig file with the administrator’s username and password to access the IIS which helps code to add a sub domain name in the particular website.

Method 2. Go to Application Pools then find your website and go to property. Click Identity tab and write window users login username and password to give access to this website for modification.

You can also search users by clicking browser then click on search select the particular user to login into the website. Save the setting and now your work is completed and everything depends on coding now.

Hope this helps you lot.

==Jagdeep Mankotia

This example will help you to create tabs in C#.

   <title>AjaxTabs </title>
                         Thisis my First Tab !!
                         Thisis my Secont Tab !!

        functionOnChanged(sender, args)
              sender.get_clientStateField().value= sender.saveClientState();


Hope this example will help you lot to create tabs in C#

==Jagdeep Mankotia