Test

Using this System SP we can delete or select all table data from a SQL SERVER database.

EXECUTE sp_MSforeachtable ‘select * from ?’

EXECUTE sp_MSforeachtable ‘DELETE FROM ?’

SQL parameter using XML in c# .NET

DB (save using XML parameter) C#,sql .Good method.

Stored Procedure

set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO

CREATE PROCEDURE [dbo].[p_app_HonorsAwardsUpdate]

    @XML ntext,
    @UserId int

AS
BEGIN
           Declare @NameofHonour1 varchar(100)
           Declare @NameofHonour2  varchar(100)
           Declare @NameofHonour3 varchar(100)
           Declare @NameofHonour4  varchar(100)
           Declare @NameofHonour5 varchar(100)
         
        — calling the Sp for taking data from xml file
        DECLARE @DocID INT
        BEGIN TRAN
            EXEC SP_XML_PREPAREDOCUMENT @DocID OUTPUT, @XML
      
            SELECT

                   @NameofHonour1 = NameofHonour1,
                   @NameofHonour2 = NameofHonour2,
                   @NameofHonour3 = NameofHonour3,
                   @NameofHonour4 = NameofHonour4,
                   @NameofHonour5 = NameofHonour5
                 
            FROM

            OPENXML (@DocID, ‘root/HonorsAwards’)

            WITH
                 (
                     NameofHonour1 varchar(100)
                    ,NameofHonour2  varchar(100)
                    ,NameofHonour3 varchar(100)
                    ,NameofHonour4  varchar(100)
                    ,NameofHonour5 varchar(100)         
                    
                  )

              
        UPDATE [dbo].[Applications]
        SET
            [NameofHonour1]=@NameofHonour1
           ,[NameofHonour2]=@NameofHonour2
           ,[NameofHonour3]=@NameofHonour3
           ,[NameofHonour4]=@NameofHonour4
           ,[NameofHonour5]=@NameofHonour5
         
            where [UserID]=@UserId

  
            SET NOCOUNT ON;

            IF @@ERROR>0
            BEGIN
            ROLLBACK TRAN
            END
            ELSE
            BEGIN
            COMMIT TRAN
            END

            EXEC SP_XML_REMOVEDOCUMENT @DocID
    END

============================================================
Business Layer – BLHonorsAwards
using System;
using System.Collections.Generic;
using System.Text;

namespace NSEPBusiness
{
   public class BLHonorsAwards
    {
        #region Local Variables Declaration

        private int intUserId;           
        private string strNameofHonour1;
        private string strNameofHonour2;
        private string strNameofHonour3;
        private string strNameofHonour4;
        private string strNameofHonour5;
        NSEPDataAccess.DAHonorsAwards ObjHonorsAwards = new NSEPDataAccess.DAHonorsAwards();
     
        #endregion

        #region Properties
 
        public int IntUserId
        {
           get { return intUserId; }
           set { intUserId = value; }
        }
        public string StrNameofHonour1
        {
            get { return strNameofHonour1; }
            set { strNameofHonour1 = value; }
        }      
        public string StrNameofHonour2
        {
            get { return strNameofHonour2; }
            set { strNameofHonour2 = value; }
        }      
        public string StrNameofHonour3
        {
            get { return strNameofHonour3; }
            set { strNameofHonour3 = value; }
        }     
        public string StrNameofHonour4
        {
            get { return strNameofHonour4; }
            set { strNameofHonour4 = value; }
        } 
        public string StrNameofHonour5
        {
            get { return strNameofHonour5; }
            set { strNameofHonour5 = value; }
        }

        #endregion

        #region CreateXML

        public string CreateXml()
        {
            StringBuilder xml = new StringBuilder();
            try
            {
                xml.Append(“<root><HonorsAwards NameofHonour1=\””);
                xml.Append(StrNameofHonour1);
                xml.Append(“\” NameofHonour2=\””);
                xml.Append(StrNameofHonour2);
                xml.Append(“\” NameofHonour3=\””);
                xml.Append(StrNameofHonour3);
                xml.Append(“\” NameofHonour4=\””);
                xml.Append(StrNameofHonour4);
                xml.Append(“\” NameofHonour5=\””);
                xml.Append(StrNameofHonour5);
                xml.Append(“\”/></root>”);

                return (xml.ToString());

            }
            catch (Exception err)
            {

                throw err;
            }

        }

        #endregion

        #region Update HonorsAwards

        public void Save()
        {
            ObjHonorsAwards.SaveRegistration(CreateXml(), IntUserId);
        }

        #endregion

    }
}
 

=========================================================

DataAccessLayer – DLHonorsAwards
using System;
using System.Collections.Generic;
using System.Text;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Configuration;

namespace NSEPDataAccess
{
    public class DAHonorsAwards
    {
        string connectionString = @”server=192.168.0.235\SQLExpress;database=NSEP_05June07;uid=sa;pwd=assyst;”;
        public int SaveRegistration(string strXml, int userId)
        {
            SqlParameter[] sqlParam = new SqlParameter[2];
            sqlParam[0] = new SqlParameter(“@XML”, strXml);
            sqlParam[1] = new SqlParameter(“@userId”, userId);
            int inserted = 0;
            inserted = (int)SqlHelper.ExecuteNonQuery(connectionString, “p_app_HonorsAwardsUpdate”, sqlParam);
            return inserted;
        }

    }
}
 
Presentation Layer – HonorsAwards

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class HonorsAwards : System.Web.UI.Page
{
    NSEPBusiness.BLHonorsAwards objHonorsAwards = new NSEPBusiness.BLHonorsAwards();
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    #region Methods  
  
    public void AddHonorsAwards()
    {
        objHonorsAwards.IntUserId = 191;
        objHonorsAwards.StrNameofHonour1 = txtNameofHonour1.Text;
        objHonorsAwards.StrNameofHonour2 = txtNameofHonour2.Text;
        objHonorsAwards.StrNameofHonour3 = txtNameofHonour3.Text;
        objHonorsAwards.StrNameofHonour4 = txtNameofHonour4.Text;
        objHonorsAwards.StrNameofHonour5 = txtNameofHonour5.Text;

    }
 
    #endregion

    protected void btnSubmitRegistration_Click(object sender, EventArgs e)
    {
        AddHonorsAwards();      
        objHonorsAwards.Save();
    }
}
 

Q. Are private class-level variables inherited?

Yes ,But they are not accessible.They are  not visible or accessible via the class interface.

Q.Describe the accessibility modifier “protected internal”.

They are avilable to classes which are with in the  the same assembly and are derived from the specified base class.

 What’s the top .NET class that everything is derived from?

System.Object;

 Q.What does the term immutable mean?

The data value may not be changed, Note:The variable value may be changed  but the original immutable data values was discarded and new data value was created in the memmory.

Q. What’s the difference between System.String and stem.Text.StringBuilder classes?

String is imutable. but the System.text.stringbuilder was designed with the purpose of having a mutable string where a verity of operation can be performed.

 System.text.stringbuilder is very efficient if there is a large amount of string operation is to be perfromed (since it is mutable)  on the other hand string is mutable so each time  string changes the new instance of string will be created in memmory.

Q. Can we store multiple data type in a array?

   No

Q. What is the difference between system.Array.CoptTo() and System.array.clone() ?

The Clone() method will return a new array (a shallow copy) of object containing all the elements in the original array. The CopyTo() mehod will copies the elements into another existing arraay. Boath perfroming a shallow copy.

Shallow Copy means the contents (each array element) contain references to the same object as the elements in the original array. A deep copy wouls create a new instence of each element’s object resulting in a different,yet identical object.

Q . What is nhibernate ?

 It is an Object Relation Mapper (ORM) for .NET environment. 

Q. How can you sort the elements of the array in desending order ?

By calling sort() and Reverse() methods.

Q. What is the .NET collection class that allow an element ti access using a unique key ?

HashTables

Q. Will the finally block executed if the error will not occured ?

Yes 

Q. Can multiple cath blocks be executeed for a single try block?

No,Control is transfered to finally (if there is any finally).

Q. Explain three service blocks which are commonly know as three-tier application ?

                                  Class Questions

Q. What is the syntax to inherit from a class in C#?

Place a colon and then the name of the base class

Eg: NewClass Name:Name of Base  Class

Q.Can you prevent your class from  being inherited from other class ?

Yes, The keywod “Sealed” will prevent the class from being executed.

Q. Can you allow  a class to be inherited and prevent the methods being being over-riden ?

Yes, Just leave the class public and put all methods as sealed.

Q. What is an abstract class ?

A class that cannot be instantiated . An abstract class is class that must be inherited and have the methods over-riden. An abstract class is essentially a blue print for a  class without any implementation.

Q. When do you absolutely have to declare a class as abstract?

1.When the class itself is inherited from an abstract class,But not all base abstract  methods have been onherited .

2. When atleast one of the method in the class is abstract.

Q.What is an interface class ?

Interfaces, like classes defines a set of properties, methods and events. But unlike classes interfaces do not provide implementation. They are implemented by the class and they are defined as the seperate entities from the class.

Q. Why cant you specify the accessibelity modifiers for  mehods inside the interfaces?

They all must be public and are therefore public by default.

Q.Can you inherit multiple interfaces ?

Yes .NET support multiple interfaces.

Q.What is the difference between interface and abstract class ?

In Interface class, all methods are abstract – no implementation. In abstract class some methods to be concrete. In interface class no accessebelity modifiers allowded. An abstract class may have accessebelity modifiers.

Q.What is the difference between struct and a class?

Structs are value type variables and thus saved on the stack, addidtional overhead but faster retrival.And another difference is that struct cannot be inherited.

Q. What is singletone pattern?

It is a software design pattern to restrict initiation of a class to one object.

 

 

         Method and Property Questions

Q. What does the keyword  “virtual” declares for a method or a property ?

The method or property can be overiden.

Q. How is method overriding is different from method overloading ?

When overriding a method you can change the behaviour of the method  for the derived class.Overloading a method is simply having a method with same name with in the class with differenet signatures.

Q.Can you declare a override method to be static if the original method is not static?

No, The signature of the virtual method remains the same (Only the keyword “virtual” will change to “override”)

Q. What are the different ways to overload a method ?

Different parameter datatype, Different number of parameter and different order of paramter.

Q. If a base class has a number of overloaded constructors and an inheriting class has a number of overloaded constructors can u enforce a call from an inherirted constructor to a specefic base constructor?

Yes,Just place a colon and then a keyword base (parameter list to invoke the apropriate constructor)  in a overloade constructordefenetion inside the inherited class

 

              Events and Delegates

Q. What is deligate?

A deligate object encapsulates a reference to a method.

Q. What is multi cast deligates?

A deligate that has multiple handlers assigned to it. Each assisgned handler (method)  is called.

       XML Questions

Q. IS XML case sensitive ?

Yes

Q. What is the difference between DOM parser and SAX parser?

DOM (Document Object Model) will create an internal representation of an XML Document. And it is good for small XML files but because of the whole representaion is in memmory, it is not recommented for very large document. It reads the whole XML document and returns a DOM tree representation of the document. It reads the file before processing.

SAX(Simple API for XML) is a serial acess parser. SAX provide a mechanism for reading the XML document it is a popular alternative to the DOM. It works incremently and generates events that are passed to the application. It will not create data representation of XML content so some preograming is reqiured.  However, It provides stream processing and partial processing which cannot done by the DOM parser.

Q. What is Xpath?

Xpath is used to navigate through the elemets and attributes in an XML DOcument.

XSL is a language for expressing style sheet.An XSL style sheet is , like with CSS, a file that describes how to display a XML document of a given type.

XSLT: A transformed language for XML documents. Originally intended to perform complex styling operations. (A language for transforming XML document into another XML documents)

Q. What is a DTD?

The DTD (Document Type Declaration) contains declarations that provide a grammar for a class of documets. This grammar is known as Document Type Declarations or DTD.

Q. What is a Schema?

XML Schema express shared vocabularies and allow mechines to carry out rules made by people. They provide a means for defining the structure contents and semantics of XML document.

In short Schemas are richer and powerful of describing information than what is possible with DTDs.

Q. How do you Parse/Validate the XML document?

The only way to Validate the XML Document is to parse the XML document by DOM or SAX parseres.

 

Q. Differences Between XML and HTML

XML HTML
User definable tags Defined set of tags designed for web display
Content driven Format driven
End tags required for well formed documents End tags not required
Quotes required around attributes values Quotes not required
Slash required in empty tags Slash not required

Q. Discribe the role that XSL can play  when dynamically generating HTML pages  from a relational Database?

Querying the datbase and formatting the result set so that it can be validated as an XML allww the developers to transelate the data in an HTML table l usung the XSLT rules. Sothat the format of the HTML table can be modified without changing the Query or application code since the docment logic rendering loging is isolated to the XSLT result.

Q. What is SOAP and how does it relates to XML?

The Simple Object Access Protocol (SOAP) is a formating protocol. Before transmitting data it converts into XML formate. Webservice work with the help of XML and HTTP SOAP is formating protocol and HTTP is the transmision protocol. A SOAP consist of 3 components an envolope, a set of encoding rules and a convension for remote representing remote procedure calls.

Debugging & Testing Questions

Q. What Debugging tool comes with the .NET SDK?

CorDBG command-line debugger . To use the CorDBG you must compile the original c# file  using the debugg switch.

Q. What does assert() method do?

In debug compilation assert take in a Boolean as a parameter and shows the error dialog if the error dialog if the condition is flase.The program continuse if there is no any error.

Q. What is the difference betweem the Trace class and debugg class?

Documentation looks the same. Use Degugg for the debugg bulds and use Trace for boath debugg and release Builds.

Q. How do you Debugg an ASP.NET web application?

Attach the aspnet_wp.exe process to the dbgCLR debugger.

Q. What are the 3 testcases you should gothrough the unit testcase?

Positive Test Case,Negative Test Cae and Exception Test Case

 Q. Can you change the value of a variable while debugging a C# application?

Yes, Just go to the immediate Window and put the new valus for the variables.

 

ADO.NET and Database Questions

Q. What is the role of DataReasder class in ADO.NET connections?

It returns a readonly ,forward only rowset from the datasource.A DataReader provide fast Acess when a frward only sequential access is needed.

Q. What are the advantages and disadvantages of Microsoft provided data provioder classes in ADO.NET?

SQLServer.NET data provider is high-speed and robust, but requires SQL Server license purchased from Microsoft. OLE-DB.NET is universal for accessing other sources, like Oracle, DB2, Microsoft Access and Informix.  OLE-DB.NET is a .NET layer on top of the OLE layer, so it’s not as fastest and efficient as SqlServer.NET.

Q. Explain the ACID properties?

A:[Atomic]It is one unit of work. It does not depent on previous and following transactions.

C:[Consistent] The Data will be consistent ie: Either data is commited or rollback there is not a inbetween state when something has updated or Inserted.
I:[Isolated] This means that no operations out side a transaction can’t ever see the data in anintermediate state.
D: [Durabelity] It means the result of a compleeted transaction are permenent and can survive future system failures

Q. Between SQL Authentication and Windows authentication which one is trusted and which one is untrusted?

Windows Authentication is the Trusted one because the Username and Password are checked with the Active Directory. SQL server authentication is untrusted since, in SQL server Authentication SQL server is the only verifier of username and Passord.

 

Assembly Questions

Q. What is a satellite assembly?

When you make external sets of resources for your application to use (that is, resources that are not a part of your main assembly), these are referred to as ‘satellite assemblies’.

Q. What namespaces are requiered for creating localized applocations?

 System.Globalization and System.Resources.

Q. What is the smallest unit of execution in .NET assembly

an Assembly.

Q. When shold you call a Garbage Collector?

As a good practice,You should not use Garbade Collector. If you are using large objects and operation and if you want to explicitly dispose the objects you can use Garbage collector. But it is noot recommented.

Q. What is boxing?

Converting value type to a reference type is called Boxing.

Eg:- int i=222;

object O=(object)i;

Q. What is strong named  assembly?

A strong name consists of the assembly’s identity — its simple text name, version number, and culture information (if provided) — plus a public key and a digital signature.You can ensure that a name is globally unique by signing an assembly with a strong name.

Q. What will happens in memmory when you box or unbox a value type?

Boxing converts the value type to reference type, thus sorting the objects in Heap. Unboxing converts the reference type to value type, thus sorting the values on the stack.

Q. What is the difference between DLL and EXE?

DLL is a in-process server while exe is a out-process server it means dll works within the thread of application while exe works after creating its own thread.Dll is not affect efficiency of application b’caz not taking extra space in memory to runif dll fails the application became fail if exe fails dll doesn’t fail because its not work within the thread of application but the part of the exe could not work properly

You can run an application in runtime using this simple code

System.diagnocis.process.start(Filename as string);

Authentication

Authentication is the process of discovering and verifying the identity of a principal by examining the user’s credentials and validating those credentials against some authority. The information obtained during authentication is directly usable by your code. That is, once the identity of the principal is discovered, you can use .NET Framework role-based security to determine whether to allow that principal to access your code.

Authorization

Authorization is the process of determining whether a principal is allowed to perform a requested action. Authorization occurs after authentication and uses information about the principal’s identity and roles to determine what resources the principal can access. You can use .NET Framework role-based security to implement authorization

Check that GC.Collect is not called directly, instead the he garbage collector is allowed to determine when it needs to run.  

If you have a particular niche scenario where you have to call GC.Collect, consider the following:

  • Call GC.WaitForPendingFinalizers after you call GC.Collect. This ensures that the current thread waits until finalizers for all objects are called.
  • After the finalizers run, there are more dead objects (those that were just finalized) that need to be collected. One more call to GC.Collect collects the remaining dead objects.
  •  System.GC.Collect(); // This gets rid of the dead objects
       System.GC.WaitForPendingFinalizers(); // This waits for any finalizers to finish.
       System.GC.Collect(); // This releases the memory associated with the objects that were just finalized.

    Welcome to WordPress.com. This is your first post. Edit or delete it and start blogging!