Tuesday, November 12, 2013

Create First Web API Application

For Creating Web Api first check you have MVC 4  version installed on your machine.

First select new Porject and select MVC4WebAppliction.

After thet select Web API under next wizard. after creation this will look like below image


For creating API we need to workin only one controller file i.e. ValuesController. I have created single get method for learning puspose First Create Customer Class file under model and refrence to on your controller file



After Implementation of Get Methods you need to execute/test this page, you will found API URi like this...

http://localhost:56880/api/Values

After success full creation of Web APi now its time to integrate this on your application.

For demo purpose i have created a page in a same project you can implement this on any other sites also.

In my case for Accessing the created API  need to create Controller APITestController and View for viewing purpose just like below image



once you created the view page now you need to write some code for accessing the API, for example i am writing here in jQuery like below image

Thursday, November 7, 2013

Update All Column Values of a table in SQL

You can very easily generate SQL to do the updates, to save you a lot of typing. You can whip up something like this very quickly:

SELECT 'UPDATE [Name] SET ' + COLUMN_NAME + ' = NULL WHERE + ' + COLUMN_NAME + ' = '' ''' FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = 'Name' AND IS_NULLABLE = 'YES' AND DATA_TYPE IN ('char', 'nchar', 'varchar', 'nvarchar')

Just replace "Name" with the name of your table, and run. Copy the output into a SQL Server Query Manager window, and run it.
The above will update every column of every row in the table to be NULL where the column contains exactly one space.

Tuesday, November 5, 2013

Open link in new window or tab using Javascript


  <script type="text/javascript" language="javascript">
    function MM_jumpMenu(targ, selObj, restore) { //v3.0
       if (selObj.options[selObj.selectedIndex].value.indexOf("http:") >= 0) {
           eval(targ + ".location='" + selObj.options[selObj.selectedIndex].value + "'");
           if (restore) selObj.selectedIndex = 0;
        }
    }
 </script>


 <select onchange="MM_jumpMenu('window.open()',this,0)" size="1" id="width" name="Width">        
      <option>Select an Option</option>
      <option>Child Plan</option>
      <option value="http://google.co.in">--Google</option>
      <option value="http://www.maxlifeinsurance.com/Plans/insurance-plans/child-insurance/shiksha_plus.aspx">--Shiksha Plus II</option>
      <option value="http://www.maxlifeinsurance.com/Plans/insurance-plans/child-insurance/college-money-back.aspx">--College Plan</option>

     <option>Growth Plan</option>
    <option value="http://www.maxlifeinsurance.com/Plans/insurance-plans/child-insurance/shiksha_plus.aspx">--Flexi Fortune</option>
    <option value="http://www.maxlifeinsurance.com/Plans/insurance-plans/growth/fasttraclplan.aspx">--Fast Track</option>
  </select>

Friday, October 25, 2013

Web Farm and Web Garden

Web Farm

After developing our asp.net web application we host it on IIS Server. Now one standalone server is sufficient to process ASP.NET Request and response for a small web sites but when the site comes for big organization where there an millions of daily user hits then we need to host the sites on multiple Server. This is called web farms. Where single site hosted on multiple IIS Server and they are running behind the Load Balancer.


Web Garden

All IIS Request process by worker process ( w3wp.exe). By default each and every application pool contain single worker process. But An application pool with multiple worker process is called Web Garden. Many worker processes with same Application Pool can sometimes provide better throughput performance and application response time. And Each Worker Process Should have there own Thread and Own Memory space.

Cursor Trigger and Joins well explained

What are cursors? Explain different types of cursors. What are the disadvantages of cursors? How can you avoid cursors?
Ans : Cursors allow row-by-row prcessing of the resultsets.
Types of cursors: Static, Dynamic, Forward-only, Keyset-driven. See books online for more information.
Disadvantages of cursors: Each time you fetch a row from the cursor, it results in a network roundtrip, where as a normal SELECT query makes only one rowundtrip, however large the resultset is. Cursors are also costly because they require more resources and temporary storage (results in more IO operations). Furthere, there are restrictions on the SELECT statements that can be used with some types of cursors.Most of the times, set based operations can be used instead of cursors
.
What are triggers? How to invoke a trigger on demand?
Ans : Triggers are special kind of stored procedures that get executed automatically when an INSERT, UPDATE or DELETE operation takes place on a table. Triggers can't be invoked on demand. They get triggered only when an associated action (INSERT, UPDATE, DELETE) happens on the table on which they are defined.Triggers are generally used to implement business rules, auditing. Triggers can also be used to extend the referential integrity checks, but wherever possible, use constraints for this purpose, instead of triggers, as constraints are much faster.

What is a join and explain different types of joins.
Ans : Joins are used in queries to explain how different tables are related. Joins also let you select data from a table depending upon data from another table.
Types of joins: INNER JOINs, OUTER JOINs, CROSS JOINs. OUTER JOINs are further classified as LEFT OUTER JOINS, RIGHT OUTER JOINS and FULL OUTER JOINS.

What is self join ?
Ans :Self join is just like any other join, except that two instances of the same table will be joined in the query.

HTML5 Learning

Very well explained  tutorials links are below

http://www.html5canvastutorials.com/tutorials/html5-canvas-lines/
https://developer.mozilla.org/en/Canvas_tutorial/Drawing_shapes
http://www.codecademy.com
http://thecodeplayer.com

System.InvalidOperationException While writing connection string


Error:- System.InvalidOperationException: Instance failure.
Sol:-
When i had this problem as i have provided a double \\ in connection string just check how you are providing the connection string in a config file i.e. Data Source=.\\SQLEXPRESS;" - It's the double \\. That's an escape sequence in C#.

if you found this issue on code behind file for avoiding you need to write your code like this @"\SQlEXPRESS"
hope it works for you now.