Wednesday, July 14, 2010

New Features in ASP.Net 4.0 - PART 1

Search Engine Optimization:

1.Meta data Keyword and Descrption :
Adding MetaKeyword and MetaDescription Using Page object.Meta keywords and description are most important components of a page when we want to make it search engine friendly. Every search engine will look for these tags to know more information of the page contents. ASP.Net 2.0 introduced a new feature where one can add these tags from the code behind using HtmlMeta class. It would have been better if we are able to do this through Page directive (Page class). ASP.Net 4.0 added 2 new properties on the Page object to let you define the Meta keywords and Description.

Refer the code below,
protected void Page_Load(object sender, EventArgs e){
Page.MetaKeywords = "asp.net,C#";
Page.MetaDescription = "This is an asp.net site that hosts asp.net tutorials.";
}
OR
<%@ Page Language="C#" AutoEventWireup="true" MetaKeywords="asp.net,C#" MetaDescription="This is an asp.net site that hosts asp.net tutorials" CodeFile="Default.aspx.cs" Inherits="_Default" %>
The above code will add the meta tags in the output html.

Note
We can still do this in earlier version by defining a BasePage class. 
Enabling Viewstate for Page level and control level: 
    ViewState is one of the important factors if we start looking at improving the performance our asp.net site. Till ASP.Net 3.x, we have EnableViewState property both at Page level and server control level to control the view state. Disabling the ViewState at page level will disable the viewstate to all the page controls. In order to improve the performance, one need to switch off the viewstate for individual control for which saving the viewstate is not necessary and hence disabling viewstate at page level is not a suitable option. To overcome this difficulty, asp.net 4.0 added a new property to Page object and controls called ViewStateMode.
This property can take 3 values: 
  1. Enabled :This value will enable the view state. This is the default value for the Page object. 
  2. Disabled : This value will disable the viewstate. 
  3. Inherit : This value will make the control to inherit the setting of the parent. This is the default value for a control.
With this property, we can disable the viewstate for the page and enable it for the control if only required.
Consider the following code,
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ViewStateTest.aspx.cs" ViewStateMode="Disabled" Inherits="ViewStateTest" %>


ViewStateMode="Enabled"
Text="Default Text"
CodeBehind
protected void Page_Load(object sender, EventArgs e){
if (!IsPostBack){
Label1.Text = "Text Assigned in CodeBehind";
Label2.Text = "Text Assigned in CodeBehind";
}}
When the page executed we will get the following output,
Text Assigned in CodeBehind
Text Assigned in CodeBehind
When the button is clicked,
Text Assigned in CodeBehind
Default Text
Since, the viewstate is disabled at page level (Page object) and the viewstate is enabled for “Label1” we will get the above output on Button click. Please note that if we have not set the value, the default will be “inherit” (for Label2).
Note
If we disabled the viewstate through EnableViewState property, setting any values for ViewStateMode property will make no impact.

Tuesday, June 15, 2010

Reset the identity on Table

dbcc checkident (table_1, reseed, 0)

Monday, May 3, 2010

How Web service create Proxy and dll Using WSDL?


In this  post  we are going to understand  how create web service proxy and consume service into console application(Client).
Building Web Service Clients using the .NET Framework:
            Clients communicate with Web Services using standard web protocols, using XML-encoded messages to send and receive messages between themselves. This makes it possible for client applications running on any platform to access web services as long as they use standard web protocols, and understand the XML-encoded messages. 
          There are three protocols that web clients can use to communicate with web services namely,
  1. HTTP GET
  2. HTTP POST 
  3. SOAP.
          The various steps that are involved in creating a Web Service Client using C# and the .NET Framework are as follows:
  1. Generate a Proxy for the Web Service
  2. Compile the Proxy as a DLL library
  3. Create a Visual C# - Console Application Project
1. Generate a Proxy class for the Web Service
.NET SDK provide WSDL.exe utility to generate proxy source code for an existing web service.WSDL.exe utility take a WSDL file as input to generate proxy source code.
we can generate proxy source code for the actual web service as shown below:
1.Go to .NET Command prompt
2.Type following command to create proxy source code
WSDL http://hostServer/WebserviceRoot/WebServiceName.asmx?WSDL
(Created new proxy class file and it's located into default .NET command prompt folder)
 OR
WSDL /out:myProxyClass.cs http://hostServer/WebserviceRoot/WebServiceName.asmx?WSDL
if we want to create proxy class as specific user defined name, we can specify class name in next to out keyword.

2. Compile the Proxy class as a DLL Library
          We can compile the C# generated proxy class file into a dynamic link library (DLL) and then add a reference to this DLL to any project we want to consume service.
3. Create a Visual C# - Console application
  1. Create a new Visual C# console application in order to consume web service and add a reference to the already created DLL(based on point no.1 & 2).
  2. We create an instance of the proxy class and call functionality wherever required.
  3. Build the project file and run the client.

Thursday, April 29, 2010

Difference Between URI and URL

URI- Uniform resource Identifier is a superset of URL and URN
e.g.- products/books/detail.html
    It is not a URL because it does not specify how to retrieve the resource.

URL – http://www.xyz.com/products/books/detail.html
is a URL because it specifies how to retrieve the resource

URN- e.g. ISBN:1-9211009-59 is a URN because it uniquely identifies this book.

We can get this to use following code :

System.out.println(“URI : “+ httpRequestObj.getRequestURI());
System.out.println(“URL : “+ httpRequestObj.getRequestURL());

IN vs Exists

IN:

Returns true if a specified value matches any value in a subquery or a list.

Exists:

Returns true if a subquery contains any rows.

What is INDEX ?

Index is created on existing table to retrieve row quickly.

For e.g. There are thousands of records in a table, retrieving information will take long time. Therefore Index has created on column which are accessed frequently. So that the information able to retrieve quickly. Index can be created on a single column or group of columns. When index is created, it first sort the data and then it assigns RowId for each row.

Syntax :
CREATE INDEX index_name
ON table_name (column_name1,column_name2...);

There are two type of index available in sql namely like
1.Clustered Indexes
2.Non clustered Index

Clustered Index :
            It can be created using "create index ..." syntax.
Non Clustered Indexes :
            They are created when a column is explicitly defined with PRIMARY KEY, UNIQUE KEY Constraint which is not based on sorted record but on a bookmark.

Note:
1) Even though sql indexes are created to access the rows in the table quickly, they slow down DML operations like INSERT, UPDATE, DELETE on the table, because the indexes and tables both are updated along when a DML operation is performed. So use indexes only on columns which are used to search the table frequently.
2) If we have less data, not required to create indexes.
3) In oracle database you can define up to sixteen (16) columns in an INDEX.

Monday, April 5, 2010

10 Deadly Sins of Negative Thinking

Life could be so much better for many people, if they would just spot their negative thinking habits and replace them with positive ones.

Negative thinking, in all its many-splendored forms, has a way of creeping into conversations and our thinking without our noticing them. The key to success, in my humble opinion, is learning to spot these thoughts and squash them like little bugs. Then replace them with positive ones. You’ll notice a huge difference in everything you do.

Let’s take a look at 10 common ways that negative thinking emerges — get good at spotting these patterns, and practice replacing them with positive thinking patterns. It has made all the difference in the world for me.

10 Deadly Sins of Negative Thinking

1. I will be happy once I have _____ (or once I earn X).

Problem: If you think you can’t be happy until you reach a certain point, or until you reach a certain income, or have a certain type of house or car or computer setup, you’ll never be happy. That elusive goal is always just out of reach. Once we reach those goals, we are not satisfied — we want more.

Solution: Learn to be happy with what you have, where you are, and who you are, right at this moment. Happiness doesn’t have to be some state that we want to get to eventually — it can be found right now. Learn to count your blessings, and see the positive in your situation. This might sound simplistic, but it works.
2. I wish I were as ____ as (a celebrity, friend, co-worker).

Problem: We’ll never be as pretty, as talented, as rich, as sculpted, as cool, as everyone else. There will always be someone better, if you look hard enough. Therefore, if we compare ourselves to others like this, we will always pale, and will always fail, and will always feel bad about ourselves. This is no way to be happy.

Solution: Stop comparing yourself to others, and look instead at yourself — what are your strengths, your accomplishments, your successes, however small? What do you love about yourself? Learn to love who you are, right now, not who you want to become. There is good in each of us, love in each of us, and a wonderful human spirit in every one of us.

3. Seeing others becoming successful makes me jealous and resentful.

Problem: First, this assumes that only a small number of people can be successful. In truth, many, many people can be successful — in different ways.

Solution: Learn to admire the success of others, and learn from it, and be happy for them, by empathizing with them and understanding what it must be like to be them. And then turn away from them, and look at yourself — you can be successful too, in whatever you choose to do. And even more, you already are successful. Look not at those above you in the social ladder, but those below you — there are always millions of people worse off than you, people who couldn’t even read this article or afford a computer. In that light, you are a huge success.

4. I am a miserable failure — I can’t seem to do anything right.

Problem: Everyone is a failure, if you look at it in certain ways. Everyone has failed, many times, at different things. I have certainly failed so many times I cannot count them — and I continue to fail, daily. However, looking at your failures as failures only makes you feel bad about yourself. By thinking in this way, we will have a negative self-image and never move on from here.

Solution: See your successes and ignore your failures. Look back on your life, in the last month, or year, or 5 years. And try to remember your successes. If you have trouble with this, start documenting them — keep a success journal, either in a notebook or online. Document your success each day, or each week. When you look back at what you’ve accomplished, over a year, you will be amazed. It’s an incredibly positive feeling.

5. I’m going to beat so-and-so no matter what — I’m better than him. And there’s no way I’ll help him succeed — he might beat me.

Problem: Competitiveness assumes that there is a small amount of gold to be had, and I need to get it before he does. It makes us into greedy, back-stabbing, hurtful people. We try to claw our way over people to get to success, because of our competitive feelings. For example, if a blogger wants to have more subscribers than another blogger, he may never link to or mention that other blogger. However, who is to say that my subscribers can’t also be yours? People can read and subscribe to more than one blog.

Solution: Learn to see success as something that can be shared, and learn that if we help each other out, we can each have a better chance to be successful. Two people working towards a common goal are better than two people trying to beat each other up to get to that goal. There is more than enough success to go around. Learn to think in terms of abundance rather than scarcity.

6. Dammit! Why do these bad things always happen to me?

Problem: Bad things happen to everybody. If we dwell on them, they will frustrate us and bring us down.

Solution: See bad things as a part of the ebb and flow of life. Suffering is a part of the human condition — but it passes. All pain goes away, eventually. Meanwhile, don’t let it hold you back. Don’t dwell on bad things, but look forward towards something good in your future. And learn to take the bad things in stride, and learn from them. Bad things are actually opportunities to grow and learn and get stronger, in disguise.

7. You can’t do anything right! Why can’t you be like ____ ?

Problem: This can be said to your child or your subordinate or your sibling. The problem? Comparing two people, first of all, is always a fallacy. People are different, with different ways of doing things, different strengths and weaknesses, different human characteristics. If we were all the same, we’d be robots. Second, saying negative things like this to another person never helps the situation. It might make you feel better, and more powerful, but in truth, it hurts your relationship, it will actually make you feel negative, and it will certainly make the other person feel negative and more likely to continue negative behavior. Everyone loses.

Solution: Take the mistakes or bad behavior of others as an opportunity to teach. Show them how to do something. Second, praise them for their positive behavior, and encourage their success. Last, and most important, love them for who they are, and celebrate their differences.

8. Your work sucks. It’s super lame. You are a moron and I hope you never reproduce.

Problem: I’ve actually gotten this comment before. It feels wonderful. However, let’s look at it not from the perspective of the person receiving this kind of comment but from the perspective of the person giving it. How does saying something negative like this help you? I guess it might feel good to vent if you feel like your time has been wasted. But really, how much of your time has been wasted? A few minutes? And whose fault is that? The bloggers or yours? In truth, making negative comments just keeps you in a negative mindset. It’s also not a good way to make friends.

Solution: Learn to offer constructive solutions, first of all. Instead of telling someone their blog sucks, or that a post is lame, offer some specific suggestions for improvement. Help them get better. If you are going to take the time to make a comment, make it worth your time. Second, learn to interact with people in a more positive way — it makes others feel good and it makes you feel better about yourself. And you can make some great friends this way. That’s a good thing.

9. Insulting People Back

Problem: If someone insults you or angers you in some way, insulting them back and continuing your anger only transfers their problem to you. This person was probably having a bad day (or a bad year) and took it out on you for some reason. If you reciprocate, you are now having a bad day too. His problem has become yours. Not only that, but the cycle of insults can get worse and worse until it results in violence or other negative consequences — for both of you.

Solution: Let the insults or negative comments of others slide off you like Teflon. Don’t let their problem become yours. In fact, try to understand their problem more — why would someone say something like that? What problems are they going through? Having a little empathy for someone not only makes you understand that their comment is not about you, but it can make you feel and act in a positive manner towards them — and make you feel better about yourself in the process.

10. I don’t think I can do this — I don’t have enough discipline. Maybe some other time.

Problem: If you don’t think you can do something, you probably won’t. Especially for the big stuff. Discipline has nothing to do with it — motivation and focus has everything to do with it. And if you put stuff off for “some other time”, you’ll never get it done. Negative thinking like this inhibits us from accomplishing anything.

Solution: Turn your thinking around: you can do this! You don’t need discipline. Find ways to make yourself a success at your goal. If you fail, learn from your mistakes, and try again. Instead of putting a goal off for later, start now. And focus on one goal at a time, putting all of your energy into it, and getting as much help from others as you can. You can really move mountains if you start with positive thinking.

How to Exercise Your Eyes

We all know how important it is to keep our bodies fit by doing things like going to the gym, jogging, and swimming. But, did you know that you can exercise your eyes as well?

Eye exercising will keep your eyes healthy and help minimize eyestrain. Here are some easy to follow steps and tips to exercise your eyes and keep them healthy!

  • Palming Exercise - Sit comfortably on a chair. Rub your hands together until they feel warm. Close your eyes and cover them lightly with your cupped palms. Avoid applying pressure on your eyeballs. Place your palms so that the nose remains uncovered, and the eyes remain behind the slight hollow of the palms. Make sure that no light rays enter the eyes, and leave no gaps between fingers or between the edge of the palms and the nose. You may still see other lingering traces of colors. Imagine deep blackness and focus on the blackness. Take deep breaths slowly and evenly, while thinking of some happy incident; or visualize a distant scene. After your eyes see nothing but blackness, remove your palms from your eyes. Repeat the palming for 3 minutes or more.
  • Close your eyes tightly for 3-5 seconds, then open them for 3-5 seconds. Repeat this 7 or 8 times.
  • Close your eyes and massage them with circular movements of your fingers for 1-2 minutes. Make sure you press very lightly; otherwise, you could hurt your eyes.
  • Press three fingers of each hand against your upper eyelids, and hold them there for 1-2 seconds, then release. Repeat 5 times.
  • Sit and relax. Roll your eyes clockwise, then counter-clockwise. Repeat 5 times, and blink in between each time.
  • Focusing Exercises – Sit about 6 inches (150 mm) from the window. Make a mark on the glass at your eye level (a small sticker, black or red, would be perfect). Look through this mark and focus on something far away for 10-15 seconds; then focus on the mark again.
  • Hold a pencil in front of you at arm’s length. Move your arm slowly to your nose, and follow the pencil with your eyes until you can keep it in focus. Repeat 10 times.
  • Look in front of you at the opposite wall and pretend that you are writing with your eyes, without turning your head. It may seem difficult at first, but with a bit of practice it is really fun. The bigger the letters, the better the effect.
  • Imagine that you are standing in front of a really big clock. Look at the middle of the clock. Then look at any hour mark, without turning your head. Look back at the center. Then look at another hour mark. Do this at least 12 times. You can also do this exercise with your eyes closed.
  • Focus on a distant object (over 150 feet or 50 m away) for several seconds and slowly refocus your eyes on a nearby object (less than 30 feet or 10 m away) that’s in the same direction. Focus for several seconds and go back to the distant object. Do this 5 times.
  • Focus on an object in the distance (as far as possible) with a low contrasting background. Do this for a few minutes every half hour or so. This does not improve your vision, nor does any other technique. It can, however, maintain your best eyesight level during the day and prevent significant further vision deterioration.
  • Make up and down eye movements starting from up to to down. Do this 8 times. Then do the side to side eye movement, starting from left to right. Repeat this 8 times. Make sure not to add pressure to your eyes! It only worsen your vision!

Tips

  • It’s more important to do the exercises regularly than to do them for a long time. Even 30-60 seconds of eye movement every hour is very helpful. For example, when your computer takes its sweet time to do something, most people just stare at the poor thing and waste the time, but you can make a few circles with your eyes. Even the first day you do this, you should notice that, when you finish working, your eyes aren’t as tired as usual.
  • Taking short breaks from near work (e.g. staring at a computer monitor) to stare out to the distance also relieves some strain.
  • Palming is a good method to help your eyes feel better. You close your eyes and put your palms over them, this will rest your eyes.
  • Blink the eyes many times.
  • Splash your eyes with cold water repeatedly when feasible, and especially when your eyes are strained.

What is the Difference Between Http and Https?

HTTP is hyper text transfer protocol which is responsible for transmitting and receiving information across the Internet. Default port for HTTP is 80.

HTTPS is secure http which is used exchanging confidential information with a server in order to prevent unauthorized access. HTTPS is Hypertext transfer protocol over secure socket layer. Default port for HTTPS is 443.

Tuesday, March 23, 2010

What is diffgram in asp.net

A DiffGram is an XML format that is used to identify current and original versions of data elements. The DataSet uses the DiffGram format to load and persist its contents, and to serialize its contents for transport across a network connection.
When a DataSet is written as a DiffGram, it populates the DiffGram with all the necessary information to accurately recreate the contents, though not the schema, of the DataSet, including column values from both the Original and Current row versions, row error information, and row order. 
The DiffGram format that is used by the .NET Framework can also be used by other platforms to send and receive information to a .NET Framework application.
When sending and retrieving a DataSet from an XML Web service, the DiffGram format is implicitly used. Additionally, when loading the contents of a DataSet from XML using the ReadXml method, or when writing the contents of a DataSet in XML using the WriteXml method, you can select that the contents be read or written as a DiffGram.

Stored Procedures Optimization Tips

# Use stored procedures instead of heavy-duty queries.
This can reduce network traffic, because your client will send to server only stored procedure name (perhaps with some parameters) instead of large heavy-duty queries text. Stored procedures can be used to enhance security and conceal underlying data objects also. For example, you can give the users permission to execute the stored procedure to work with the restricted set of the columns and data.

# Include the SET NOCOUNT ON statement into your stored procedures to stop the message indicating the number of rows affected by a Transact-SQL statement.
This can reduce network traffic, because your client will not receive the message indicating the number of rows affected by a Transact-SQL statement.


# Call stored procedure using its fully qualified name.
The complete name of an object consists of four identifiers: the server name, database name, owner name, and object name. An object name that specifies all four parts is known as a fully qualified name. Using fully qualified names eliminates any confusion about which stored procedure you want to run and can boost performance because SQL Server has a better chance to reuse the stored procedures execution plans if they were executed using fully qualified names.


# Consider returning the integer value as an RETURN statement instead of an integer value as part of a recordset.
The RETURN statement exits unconditionally from a stored procedure, so the statements following RETURN are not executed. Though the RETURN statement is generally used for error checking, you can use this statement to return an integer value for any other reason. Using RETURN statement can boost performance because SQL Server will not create a recordset.


# Don't use the prefix "sp_" in the stored procedure name if you need to create a stored procedure to run in a database other than the master database.
The prefix "sp_" is used in the system stored procedures names. Microsoft does not recommend to use the prefix "sp_" in the user-created stored procedure name, because SQL Server always looks for a stored procedure beginning with "sp_" in the following order: the master database, the stored procedure based on the fully qualified name provided, the stored procedure using dbo as the owner, if one is not specified. So, when you have the stored procedure with the prefix "sp_" in the database other than master, the master database is always checked first, and if the user-created stored procedure has the same name as a system stored procedure, the user-created stored procedure will never be executed.


# Use the sp_executesql stored procedure instead of the EXECUTE statement.
The sp_executesql stored procedure supports parameters. So, using the sp_executesql stored procedure instead of the EXECUTE statement improve readability of your code when there are many parameters are used. When you use the sp_executesql stored procedure to executes a Transact-SQL statements that will be reused many times, the SQL Server query optimizer will reuse the execution plan it generates for the first execution when the change in parameter values to the statement is the only variation.


# Use sp_executesql stored procedure instead of temporary stored procedures.
Microsoft recommends to use the temporary stored procedures when connecting to earlier versions of SQL Server that do not support the reuse of execution plans. Applications connecting to SQL Server 7.0 or SQL Server 2000 should use the sp_executesql system stored procedure instead of temporary stored procedures to have a better chance to reuse the execution plans.


# If you have a very large stored procedure, try to break down this stored procedure into several sub-procedures, and call them from a controlling stored procedure.
The stored procedure will be recompiled when any structural changes were made to a table or view referenced by the stored procedure (for example, ALTER TABLE statement), or when a large number of INSERTS, UPDATES or DELETES are made to a table referenced by a stored procedure. So, if you break down a very large stored procedure into several sub-procedures, you get chance that only a single sub-procedure will be recompiled, but other sub-procedures will not.


# Try to avoid using temporary tables inside your stored procedure.
Using temporary tables inside stored procedure reduces the chance to reuse the execution plan.




# Try to avoid using DDL (Data Definition Language) statements inside your stored procedure.
Using DDL statements inside stored procedure reduces the chance to reuse the execution plan.

# Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.
The WITH RECOMPILE option prevents reusing the stored procedure execution plan, so SQL Server does not cache a plan for this procedure and the procedure is recompiled at run time. Using the WITH RECOMPILE option can boost performance if your query will vary each time it is run from the stored procedure because in this case the wrong execution plan will not be used.



# Use SQL Server Profiler to determine which stored procedures has been recompiled too often.
To check the stored procedure has been recompiled, run SQL Server Profiler and choose to trace the event in the "Stored Procedures" category called "SP:Recompile". You can also trace the event "SP:StmtStarting" to see at what point in the procedure it is being recompiled. When you identify these stored procedures, you can take some correction actions to reduce or eliminate the excessive recompilations.