Wednesday, 6 March 2013

Methods of a 'class' in CSharp

A class is a collection of members, where members of class can be off various kinds like :
  • Fields
  • Members
  • Constructors
  • Destructors
  • Properties
  • Indexes
  • Events
  • Delegates
  • Enum
Destructor: This is also a special method present under a child class same like a constructor but constructor method gets called when object of class is created and destructor is called whenobject of class is destroyed.
   Both constructor and destructor method will exactly have the same name i.e the name of the class which they have. To differentiate between this two we use 'tidle' operation before the destructor method.

class Test
 {
    Test() 
     {
        //Constructors
     } 
   ~Test()
    {
      //Destructors
    }
}
  • Destructor methods cannot be applied with any modifirs or parameters.
  • Garbage Collector is responsible for destroying the object of class and when the object of class is being destroyed, destructor methods gets called and moreover Garbage Collector can destroy the object of class in any of the following three classes.
  1. In the end of a program's execution each and every object i.e associated with the program is automatically destroyed.
  2. Sometime in the middle of a programs execution implicit calling of Garbage Collector takes place provided the memory is full that it identifies finds unused object and destroys them.



Tuesday, 5 March 2013

Exception Handling In SQL Server

Similar to other programming languages SQL server also supports exception handling i.e handles the exceptions, provide a proper message to the user regarding exception and avoid abnormal termination of the program.
Up to SQL sever 2000, a system variable called @@Error is use to get information about the exception and handle the exception but from SQL Server 2005 onwards exception handling is done by using try catch.

Within SQL server,  a try block can have only one catch block.
Syntax:
         begin try
          <statements>
         end try
          begin catch
          <statements>
         end catch

Error Functions
To get information about raised exception a set of functions are provided, which are collectively called as Error Functions are new in SQL 2005.
  • Error_Number() : Returns the unique number of raised error.
  • Error_Message() : Returns the message associated with the current  error raised.
  • Error_Severity() : Returns the severity of the current error raised.
  • Error_State() : Returns the state of current error raised.
  • Error_Procedure() : Returns name of the procedure in which exception occurs.
  • Error_Line() : Returns the line number within the procedure where error occurs.
Geting List of SQL Server error messages:
select * from sys.messages

You can add your own error messages to the error messages list of SQL server using the stored procedure sp_add message.

Raising Errors Manually:
There are situations where system will not raise an exception for your requirement and you want to raise exception manually for this use the riase error function that has following syntax :

raiserror(msgid/msgtext,severity,state[,arguments])

Triggers

      Triggers are stored sub-programs that will be automatically executed based on specified event.

Differences between Stored Procedures, User Defined Functions and Triggers are as follows-->
  • Stored Procedures and User Defined Functions can be called by the user manually but triggers cannot be called by the user manually and they will be automatically invoked.
  • Stored Procedures can return a value with output parameters and User Defined Functions can return a value with return statement but triggers cannot return a value either with output parameters or return statement.
  • Stored Procedures, User Defined Functions can take arguments but triggers cannot take arguments.
Based on event specified on a trigger, triggers are classified into DDL triggers and DML triggers. When the trigger is created by specifying a DDL command as event then that trigger is called as DDL triggers and when a trigger is created by specifying a DML command then that trigger is called as DML triggers. 
     
      DDL triggers are new in SQL 2005. DML triggers have the following three purposes-->
  • Create procedure integrity constraints.
  • Record auditing information of a table.
  • Allow insert,update,delete on complex views.

Access Modifiers

Members that are defined in type by any scope on specific are always accessible within the type. Restrictions comes into picture only when we try to access them outside of the type. Members declared as private under a class or structure cant be access outside of the type in which they are defined and moreover there default scope is private only.

Types cant be declare as private so private can be use only on members. One point to keep in mind is that Interface cant contain any members and default scope for interface members is public.
  • Protected: Members declared as protected under a class be accessed only within the class or in a child class.Non child classes cant consume them. Types cant be declared as protected also, so this can only be used on members.
  • Internal: Members and types that are declared as internal can be consumed only within the project bot both from child or non child. The default scope for any type in C# is internal only.
  • Protected Internal: Members declared as protected will have dual scope i.e within the project they behave as internal providing access to anywhere in project outside the classes they will change to protected and still provide access to their child classes. Types cannot be declared as protected internal also. So this can also be used only on members.
  • Public: A type or member of a type if declared as public is global in scope which can be accessed from anywhere.

Monday, 4 March 2013

Stored sub programs in SQL

  • Stored subprograms are the programs that are permanently stored in the database. Execution of stored sub-programs will be fast compare to independent SQL statements.
  • Hence to perform any operation again database from the front end application like .Net it is recommended to use stored sub programs than independent SQL statements to improve the performance of application.
  •   Before executing an independent SQL statements , SQL server has to perform parsing execution plan generation and cost estimation. During Parsing it will verify syntax of statement, availability of object refers in the statement, permissions of current user to perform specified operations on specified object and data type compatibility. As all this steps takes time execution will be slow and it affects performance of application.
  • Stored procedures are classified into :
  • Stored procedures
  • User defined procedures
  • Triggers
Stored Procedure: Stored procedures are the stored subprograms that cannot return a value with return statement. A stored procedure can contain return statemnet without a value to return and purpose of this is to exit from stored procedure.

 Syntax:
create procedure<procname>[(<parameters>)]
[with encryption] as begin
<statements>
end

User-defined functions in SQL

User defined functions are stored subprograms that must return a value with return statements. User defined functions are classified functions.
  • Scalar function: This are the user defined functions that return a single value. 

  • Valued functions: This are user defined functions that returns a table.  Table valued functions are classified into inline table valued functions and multistatement table values statement.
  • Inline Table valued functions:This are the table valued functions that contain a single statement i.e the return statement with a select statement within it, whose results will be converted inline as a table.
Inline table valued function must not contain the keyword begin and end.
  • Multistatement valued functions: This are table value functions that contain multiple statements. In case of multistatemnet table values function you have to create a table in a function manual, insert rows into it and return it manual.

Sunday, 3 March 2013

Working with ASP

Sudeep had given us the task of creating an aspx page and connecting it to the database. I successfully managed to create my first aspx page within a day.. Then after i showed it to Sudeep he asked us to do some updations like putting validations,adding links of editing and deleting etc. I even completed that within a day too. Then after i showed that also to him he made it more challenging for me by asking me to add Menus. Now i am still working on it. Now its becoming more and more challenging for me and i am enjoying  working with challenges.