Microsoft Dot Net Master

Microsoft Dot Net Master
Microsoft Dot Net Master

Friday, July 15, 2011

What are the situations you will use singleton architecture in remoting ?

If all remoting clients have to share the same data singleton architecture will be used.

What are two different types of remote object creation mode in .NET ?

There are two different ways in which object can be created using Remoting :-
√ SAO (Server Activated Objects) also called as Well-Known call mode.
√ CAO (Client Activated Objects)
SAO has two modes “Single Call” and “Singleton”. With Single Call object the object is
created with every method call thus making the object stateless. With Singleton the object
is created only once and the object is shared with all clients.
CAO are stateful as compared to SAO. In CAO the creation request is sent from client
side. Client holds a proxy to the server object created on server

Which class does the remote object has to inherit ?

All remote objects should inherit from System.MarshalbyRefObject.
(I)

What is .NET Remoting ?

.NET remoting is replacement of DCOM. Using .NET remoting you can make remote
object calls which lie in different Application Domains. As the remote objects run in
different process client calling the remote object can not call it directly. So the client uses
a proxy which looks like a real object.
When client wants to make method call on the remote object it uses proxy for it. These
method calls are called as “Messages”. Messages are serialized using “formatter” class
and sent to client “channel”. Client Channel communicates with Server Channel. Server
Channel uses as formatter to deserialize the message and sends to the remote object.

What is an application domain?

Previously “PROCESS” where used as security boundaries. One process has its own
virtual memory and does not over lap the other process virtual memory; due to this one
process can not crash the other process. So any problem or error in one process does not
affect the other process. In .NET they went one step ahead introducing application domains.
In application domains multiple applications can run in same process with out influencing
each other. If one of the application domains throws error it does not affect the other
application domains. To invoke method in a object running in different application domain
.NET remoting is used.

Thursday, July 14, 2011

Difference between Stored procedures and User Defined functions

Stored procedure
A stored procedure is a program (or procedure) which is physically stored within a database. They are usually written in a proprietary database language like PL/SQL for Oracle database or PL/PgSQL for PostgreSQL. The advantage of a stored procedure is that when it is run, in response to a user request, it is run directly by the database engine, which usually runs on a separate database server. As such, it has direct access to the data it needs to manipulate and only needs to send its results back to the user, doing away with the overhead of communicating large amounts of data back and forth.

User-defined function
A user-defined function is a routine that encapsulates useful logic for use in other queries. While views are limited to a single SELECT statement, user-defined functions can have multiple SELECT statements and provide more powerful logic than is possible with views.

In SQL Server 2000
User defined functions have 3 main categories
  1. Scalar-valued function - returns a scalar value such as an integer or a timestamp. Can be used as column name in queries
  2. Inline function - can contain a single SELECT statement.
  3. Table-valued function - can contain any number of statements that populate the table variable to be returned. They become handy when you need to return a set of rows, but you can't enclose the logic for getting this rowset in a single SELECT statement.
Differences between Stored procedure and User defined functions
  1. UDF can be used in the SQL statements anywhere in the WHERE/HAVING/SELECT section where as Stored procedures cannot be.
  2. UDFs that return tables can be treated as another rowset. This can be used in JOINs with other tables.
  3. Inline UDF's can be though of as views that take parameters and can be used in JOINs and other Rowset operations.
  4. Of course there will be Syntax differences and here is a sample of that
Stored procedure

Code: SQL
CREATE PROCEDURE dbo.StoredProcedure1   /*      (       @parameter1 datatype = default value,       @parameter2 datatype OUTPUT      )   */   AS      /* SET NOCOUNT ON */      RETURN
User defined functions

Code: SQL
CREATE FUNCTION dbo.Function1      (      /*      @parameter1 datatype = default value,      @parameter2 datatype      */      )   RETURNS /* datatype */   AS      BEGIN       /* sql statement ... */      RETURN /* value */      END

Thursday, July 7, 2011

How to add javascript validation event to textbox inside Gridview?

javascript function to restrict user to type only numbers in textbox.
Code:
<script type = "text/javascript" language = "javascript">
            function numeralsOnly(evt)
            {
                evt = (evt) ? evt : event;
                var charCode = (evt.charCode) ? evt.charCode : ((evt.keyCode) ? evt.keyCode : ((evt.which) ? evt.which : 0));
                if (charCode > 31 && (charCode < 48 || charCode > 57) && (charCode != 46))
                {
                    alert("Enter numerals only in this field!");
                    return false;
                }
                return true;
            }
       </script>

the way in which it can be specified with a textbox inside a gridview:
<asp:TextBox ID="txtProjBudget" onkeypress="return numeralsOnly(event)" runat="server"  Text='<%# Eval("Proj_Exp") %>' Width="103px"></asp:TextBox>