Tuesday, June 25, 2013

Find & Replace using Regular Expression in SQL Server Management Studio



Example:
Regular Expression to find and replace all occurrences of CAST(0x0000A1D7010C33B5 AS DateTime) in a .sql file using Find/Replace dialog of SQL Server Management Studio.

Monday, March 11, 2013

Get Exception details recursively

public static string GetExceptionDetailsRecursively(Exception e)
        {
            StringBuilder sb = new StringBuilder();

            while (e != null)
            {
                sb.Append("Inner :");
                sb.Append(e.Message);
                sb.Append("\t");
                e = e.InnerException;
            }

            return sb.ToString();
        }

How to get all notes comma separated group by customer


SQL Query - How to get all notes comma separated group by customer

NoteKey CustomerKey Note LastEditedTime
1 18736673 Accout access error, Contact Technical team. 01/02/2013


SELECT n1.CustomerKey, (SELECT ','+  n2.Note+ ' Last Edited Time:' + convert(varchar(26),n2.LastEditedTime)
       FROM Note n2
       WHERE n1.CustomerKey= n2.CustomerKey
       ORDER BY CustomerKey, Note  
       FOR XML PATH('')) AS CustNote
       FROM Note n1
Group By n1.CustomerKey


Thursday, February 14, 2013

For Beginners : How to compile a .cs file without visual studio


Generate a proxy of a WCF Service



SVCUTIL.exe is the tool used to generate proxy of a WCF Service class. A simple way of creating a proxy with all default options is :
  • Open Microsoft Visual Studio Command Prompt 2010.
  • svcutil.exe [assembly name]- This will generate the .wsdl & .xsd files.
  • svcutil *.wsdl *.xsd /language:C# - This will generate the proxy class(.cs file) and output.config file.
  • Add the proxy class to your client project and copy the content of the output.config file to App.Config file.

Tuesday, December 4, 2012

Web API Sample

Web Api framework is Http based and can be accessed from broad range of clients like Browser, Mobile App etc.

REST uses some common HTTP methods to insert/delete/update/retrieve information. These Http methods are:
1.GET - Requests a specific representation of a resource
2.PUT - Creates or updates a resource with the supplied representation
3.DELETE - Deletes the specified resource
4.POST - Submits data to be processed by the identified resource

Data Type supported:

  • XML
  • JSON
  • ATOM

This sample application demonstrates how to use Web API framework to return all posts from your blog in Json format.
My Blogs
    Add Blog
    Delete Blog
    public class BlogPost
    {
       public int Id {get; set;}
       public string Title {get; set;}
       public string Content {get; set;}
       public string Labels {get; set;}
    }
    
    public namespace SampleWebApi.Controllers
    {
        using System.Net;
        using System.Net.Http;
        using System.Web.Http;
    
        
    
         public class BlogController:ApiController    
            {
                static List posts = new List  
                    {              
                        new BlogPost{ Id = 1, Title= "Web Api Framework on .NET", Content = "services exposed over plain HTTP", Labels= "" },              
                        new BlogPost{ Id = 2, Title= "MVC4", Content= "Mobile Support", Labels= "" },              
                        new BlogPost{ Id = 3, Title = "KnockoutJS", Content= "Javascript based MVVM framework", Labels= ""}          
                    };
    
    
                public BlogPost GetBlogPost(int id)
                {
                    return posts.Find(m => m.Id == id);
                }
    
                public IEnumerable GetAllPosts()        
                {              
    
                    return posts;        
                }
    
                public BlogPost PostBlog(BlogPost post)
                {
                    posts.Add(post);
                    return post;
                    
                }
    
                public void PutBlog(int id, BlogPost post)
                {
                    var blog = posts.Find(m => m.Id == id);
                    blog.Title = post.Title;
                    blog.Content = post.Content;                
                }
    
                public void DeleteBlog(int id)
                {
                    var post = posts.Find(m => m.Id == id);
                    posts.Remove(post);
                }
            }
    }
    
    
    
    

    What is new in ASP.NET 4.5

    URL - http://www.asp.net/vnext/overview/aspnet/whats-new