The .NET Framework is an environment for building, deploying, and running Web Services and other applications. It consists of three main parts: the Common Language Runtime, the Framework classes, and ASP.NET
Saturday, May 31, 2008
Polymorphism in VB.Net
We can achieve polymarphism in .Net i.e Compile time polymarphism and Runtime polymarphism. Compiletime Polymarphism achieved by method overloading. Runtime polymarphism achieved by Early Binding or Late Binding. Provide the function pointer to the object at compile time called as Early Binding.
provide the function pointer to the object at runtime called as Late Binding
class emp having the method display()
class dept having the method display()
create objects as in the main function
// Early binding
dim obj as new emp
dim ob as new dept
obj.display()-to call the display method of emp class
ob.display-to call the display method of the dept class
// Late binding
create object in the main class as
object obj
obj=new emp
obj.display()-to call the display of emp class
obj=new dept
obj.display()-to call the display of dept class
Serialization in .NET
When developing smaller applications that do not have a database (or other formal storage mechanism) or data that doesn’t need to be stored in a database (such as the state of a web application), you often still would like to save the data for later retrieval. There are many ways to do this, but many of them are subject to a lot of extra code (work) and extra time spent debugging. With .NET, there is now an easy way to add this functionality to your code with only a few lines of easily tested code. This easy way is called serialization.
Serialization is the process of storing an object, including all of its public and private fields, to a stream. Deserialization is the opposite – restoring an object’s field values from a stream. The stream is generally in the form of a FileStream, but does not have to be. It could be a memory stream or any other object that is of type IO.Stream. The format can be anything from XML to binary to SOAP.
authentications in .Net
There are 4 types of authentications.
1.WINDOWS AUTHENTICATION
2.FORMS AUTHENTICATION
3.PASSPORT AUTHENTICATION
4.NONE/CUSTOM AUTHENTICATION
The authentication option for the ASP.NET application is specified by using the tag in the Web.config file, as shown below:
other authentication options
1. WINDOWS AUTHENTICATION Schemes
I. Integrated Windows authentication
II. Basic and basic with SSL authentication
III. Digest authentication
IV. Client Certificate authentication
2. FORMS AUTHENTICATION
You, as a Web application developer, are supposed to develop the Web page and authenticate the user by checking the provided user ID and password against some user database
3.PASSPORT AUTHENTICATION
A centralized service provided by Microsoft, offers a single logon point for clients. Unauthenticated users are redirected to the Passport site
4 NONE/CUSTOM AUTHENTICATION:
If we don’t want ASP.NET to perform any authentication, we can set the authentication mode to “none”. The reason behind this decision could be: We don’t want to authenticate our users, and our Web site is open for all to use. We want to provide our own custom authentication
Monday, May 26, 2008
Data Types in .NET
Data Type is an attribute that specifies the type of data that object can hold.
System.Boolean ( 1 byte
System.Byte ( 1 byte
System.Char ( 2 bytes
System.Int16 ( 2 bytes
System.Int32 ( 4 bytes
System.Int64 ( 8bytes
System.Object ( 4bytes
System.Single ( 4bytes
System.Double ( 8bytes
System.Decimal ( 12bytes
System.DateTime ( 8bytes
System.String ( 10bytes +(2*string length)
System.ValueType ( Sum of Member sizes(User Defined Type)
Differences between Dataset and DataReader
The Dataset object is central to supporting disconnected and distributed data scenarios with ADO.NET. The Dataset is a memory-resident representation of data that provides a consistent relational programming model regardless of the data source. It can be used with multiple and differing data sources, used with XML data, or used to manage data local to the application.
The Dataset represents a complete set of data including related tables, constraints, and relationships among the tables. I think this is something that gives the advantage upon the older ADO.
ADO.NET DataReader to retrieve a read-only, forward-only stream of data from a database. Using the DataReader can increase application performance and reduce system overhead because only one row at a time is ever in memory.
Choosing a DataReader or a Dataset:
When deciding whether your application should use a DataReader (see Retrieving Data Using the DataReader) or a Dataset (see Creating and Using Dataset s), you should consider the type of functionality that your application requires.
Use a Dataset to do the following:
Remote data between tiers or from an XML Web service. Interact with data dynamically such as binding to a Windows Forms control or combining and relating data from multiple sources. Cache data locally in your application. Provide a hierarchical XML view of relational data and use tools like an XSL Transformation or an XML Path Language (XPath) Query on your data.
For more information, see XML and the Dataset . Perform extensive processing on data without requiring an open connection to the data source, which frees the connection to be used by other clients.
If you do not require the functionality provided by the Dataset . You can improve the performance of your application by using the DataReader to return your data in a forward-only read-only fashion. Although the DataAdapter uses the DataReader to fill the contents of a Dataset (see Populating a Dataset from a DataAdapter), by using the DataReader you can receive performance gains because you will save memory that would be consumed by the Dataset , as well as saving the processing required to create and fill the contents of the Dataset .
Why to use SiteMinder
SiteMinder is the user authentication and authorization component of an access management suite. SiteMinder provides policy-based authentication as well as single sign-on for all Web-based applications. SiteMinder is used in conjunction with IdentityMinder, which manages detailed user profiles, and TransactionMinder, which provides access to Web services. To integrate SiteMinder authentication within an ASP.NET application what must be done (beside the installation and configuration of the Web Agent, Policy Server, etc, of course) is to extract the SiteMinder HTTP headers from the web request and construct a Generic Principal object which holds the identity of the authenticated user.
Problems facing today’s internet business:
• Securing content
• Managing users and access control
• Customizing user’s experience
• Scaling for large/small number of users
• Integrating already existing web based systems.
• Implementation of SiteMinder will overcome all the mentioned issues what we are facing in current internet business and applications.
Why to use SiteMinder:
• SiteMinder Provides a single customized view of any portal, to a variety of users.
• It addresses key authentication, authorization and personalization requirements of building secure web sites, in a cost effective and efficient way.
• Site Minder supports a variety of platforms.
• Centralized administration
• Ease of implementation for redundant setup
• Deliver an improved user experience(Single sign on, Personalization, User registration etc)
• Provide delegated administration
• Scale for large and small projects.
• Integrate applications and improve workflow.
• Allow easier web application development.
New features in ADO.NET 2.0
1. MARS
The new Multiple Active Result Sets (MARS) feature in ADO.NET 2.0 can have multiple active commands on one connection. By using MARS, you can open a connection to the database, create a new command and process some results, create a second command and process those results, then go back to the first command and process more results. No blocking happens between the commands that share the database connection. You can use MARS support only with SQL Server 2005 systems.
2. Schemas
In ADO.NET 2.0, Microsoft has added a set of features to the standard managed code classes that you can use as an API to query database schemas and obtain information about the tables, stored procedures, data types, users, and other content of a database.
3. Bulk Insert
The SqlBulkCopy object provides a high-performance method for transferring database objects between databases or SQL Server systems. However, the object doesn't connect to the file system and thus can't be used to import flat files to SQL Server.
4. Query Notification
If records in the underlying database table change, then your Web application will display old, inaccurate data. ADO.Net 2.0 provides us with the feature where in the cache can be invalidated and the data is re-loaded in the cache when the request is made if the underlying data changes before the cache expires. SQL Server 2005 has got a SQL Broker Service feature where-in it will notify the web application that the data has changed. This helps in relieving the web application to poll to the SQL Server 2005 to check for data changes.
5. New Data Set
The indexing engine for SQL Server 2005 has been re-written which helps in reading the data much faster than earlier version. The DataTable is independently serializable and can be used in both web service and remoting scenarios. The DataTable now supports the basic methods for XML, just as the DataSet does.
6. XML Data Type Support
XML data type is just like INT or VARCHAR, and SQL Server 2005 allows in-place querying and processing of this data type using a series of XML-specific functions. There is also support for storing collections of XML schemas in the database, enabling database-based schema validation.
7. Asynchronous Support
Asynchronous support lets client applications submit queries without blocking the UI. ADO.NET 2.0 lets server applications issue multiple database requests on different threads. The support works with SQL Server 2005, SQL Server 2000, and SQL Server 7.0.
VS 2008 Certification
Visual Studio 2008 certifications are part of the ‘new generation’ of certifications, i.e. Microsoft Certified Technology Specialist (MCTS) and Microsoft Certified Professional Developer (MCPD)–the same format in which VS2005 certifications were released.
There will not be an upgrade path from MCAD or MCSD to Visual Studio 2008, but you can go from MCAD/MCSD to Visual Studio 2005, then follow a (to-be-determined) transition path to Visual Studio 2008
If you are new to certification (or just haven’t started a VS2005 or VS2008 track), take 70-536 because it is the first step for both 2005 and 2008 MCTS cert’s and is available now.
If you are partially through an MCAD or MCSD track, you can finish them. MCAD/MCSD won’t expire. However, at some point this year retirement of those exams will be announced (usually with a year’s notice) so keep that in mind, keep an eye out for a formal announcement, and get a move on. For that reason, too, It is not recommend starting a MCAD or MCSD track from the beginning now - instead consider exams in the MCTS/MCPD family.
If you work with Visual Studio 2005, start (or finish) a Visual Studio 2005 certification track. As long as you are working with VS2005 those certs will have value, one of the exams is part of your 2008 track and there will be a 2005 to 2008 option, for when/if you want to transition your certification to 2008.
If you want to start a VS2008 track from scratch (or if you are MCAD/MCSD and want to wait for 2008), you can start now on 70-536.
When to use dataset & data reader
When we need to work with few tables and most of the time you need to execute queries on these tables, you should go for the dataset.
Disconnected data access is suited most to read only instances and disconnected data access architecture is not designed to be used in the networked environment where multiple users are updating data simultaneously and each of them needs to be aware of current state of database at any time.
DataReader is more useful when you need to work with large number of tables, Database in non-uniform pattern and you need not execute the large no. of queries on few particular table.
It also depends on the nature of application. If multiple users are using the database and the database needs to be updated every time, you must not use the dataset. For this, .Net provides the connection oriented architecture.
But in the scenarios where instant update of database is not required, dataset provides optimal performance by making the changes locally and connecting to database later to update a whole batch of data. This also reduces the network bandwidth if the database is accessed through network.
Sunday, May 4, 2008
Drop un-named constraint
declare @name nvarchar(32),
@sql nvarchar(1000)
-- find constraint name
select @name = O.name
from sysobjects AS O
left join sysobjects AS T
on O.parent_obj = T.id
where isnull(objectproperty(O.id,'IsMSShipped'),1) = 0
and O.name not like '%dtproper%'
and O.name not like 'dt[_]%'
and T.name = 'MyTable'
and O.name like 'My Column%'
-- delete if found
if not @name is null
begin
select @sql = 'ALTER TABLE [MyTable] DROP CONSTRAINT [' + @name + ']'
execute sp_executesql @sql
end
-- do your ALTER TABLE here
-- replace the constraint
select @sql = 'ALTER TABLE [MyTable] ADD CONSTRAINT [' + @name + '] DEFAULT (0) FOR [MyColumn]'
execute sp_executesql @sql
Check for duplicate records
One of the very basic and common that i have seen in my mail box and in forums is what is the easiest way to find out duplicate records.
SELECT email,
COUNT(email) AS NumOccurrences
FROM users
GROUP BY email
HAVING ( COUNT(email) > 1 )
Saturday, May 3, 2008
Catch Error Functions
ERROR_NUMBER(): Returns a number associated with the error.
ERROR_SEVERITY(): Returns the severity of the error.
ERROR_STATE(): Returns the error state number
ERROR_PROCEDURE(): Returns the name of the stored procedure or trigger in which the error occurred.
ERROR_LINE(): Returns the line number inside the failing routine that caused the error.
ERROR_MESSAGE(): Returns the complete text of the error message. The text includes the values supplied for any substitutable parameters, such as lengths, object names, or times.
Try Catch Error handling
In SQL Server 2005 there is new era to Error handling. When i was working in Java i was thinkin when i am going to have try/catch concepts in SQL Server...Now we have it in SQL Server 2005. Try/Catch, similar to VB.Net error handling
BEGIN TRY
DECLARE @X INT
-- Divide by zero to generate Error
SET @X = 1/0
PRINT 'Command after error in TRY'
END TRY
BEGIN CATCH
PRINT 'Error Detected'
END CATCH
PRINT 'Command after TRY/CATCH blocks'
T-SQL Enhancements
Varchar(max), Varbinary(max)
In SQL 2000, fields over 8,000 characters used Text, Image but that involved a different programming style than smaller fields.
Now fields of type char, varchar, binary, varbinary can hold up to 2 GB storage with same programming style as small fields.