Friday, December 6, 2013

How to use SQLCacheDependency in ASP.NET MVC

Database
Database : Employee
Table : EmpDetails
Developer Command Prompt
aspnet_regsql.exe -S DBServerName -E -d database name -ed 
aspnet_regsql.exe -S DBServerName -E -d database name -t table name -et
Web.Config
  
    
      
        
          
        
      
    
  
Cache Class
public class SQLDependencyCacheProvider
    {
        private static System.Web.Caching.Cache _cache;

        public System.Web.Caching.Cache Cache
        {
            get
            {
                if (_cache == null)
                {
                    _cache = HttpRuntime.Cache;
                }

                return _cache;
            }
        }

        public T GetCacheItem(string key)
        {
            var item = Cache.Get(key);
            return (item != null) ? (T)Convert.ChangeType(item, typeof(T)) : default(T);
        }

        public void InsertCacheItem(string key, T value)
        {
            Cache.Insert(key, value, new SqlCacheDependency("Employee", "EmpDetails"));
        }
    }


Thursday, December 5, 2013

How to Configure ASP.NET Tracing for ASP.NET MVC Applications

  1. ASP.NET Application Level Tracing
  2. Writting Custom ASP.NET Trace Messages using System.Diagnostics.TraceSource class and trace sources
  3. Writting Custom ASP.NET Trace Messages using System.Diagnostics.Trace class
PRE-Requisite(Trace Complier Constant) : Trace statements (Custom tracing) require the TRACE compiler constant, but it’s on by default and you can verify that in the Build tab of the project properties window
The problem is that this setting in the .csproj file only applies to .cs files. ASP.NET uses a different compile process for .cshtml files (or .aspx files in Web Forms), and the settings for that compile process are in the Web.config file. If you don’t explicitly specify the TRACE constant there, tracing method calls in .cshtml views are ignored. Below is an example of what you have to add to the application Web.config file for a Visual Studio project that targets .NET 4.5, in order to define a TRACE constant for the .cshtml compiler:
 
   
     
     
   
 

ASP.NET Application Level Tracing

Web.Config entries

  
    
  


    
       
      
      
      
    
    
        
         
          
          
          
                   
         
       
      
        
          
          
          
        
          
    
    
      
      
    
    
      
        
        
      
    
  
C# Code
 using System.Diagnostics;
 public class AccountController : Controller
    {
        public ActionResult Index()
        {            
            TraceSource source = new TraceSource("AccountController");
            source.TraceEvent(TraceEventType.Warning, 100, "This is message logged from Account Controller");
            return View();
        }

    }
Writting Custom ASP.NET Trace Messages using System.Diagnostics.Trace class
 using System.Diagnostics;
 public class AccountController : Controller
    {
        public ActionResult Index()
        {          
            Trace.WriteLine("This is message logged from Account Controller");
            return View();
        }

    }

Thursday, July 25, 2013

Observer Design Pattern Example

Announcement Ticker
 public class Announcement
    {
        public string Company { get; set; }
        public string Content { get; set; }
        
       
    }
public class AnnouncementChangeEventArgs
    {
        private Announcement announcement;
        public AnnouncementChangeEventArgs(Announcement announcement)
        {
            this.announcement = announcement;
        }
        public Announcement Announcement
        {
            get
            {
                return this.announcement;
            }
            
        }
    }
public class AnnouncementTicker
    {
        private Announcement announcement;
        public Announcement Announcement
        {
            get
            {
                return announcement;
            }
            set
            {
                this.announcement = value;
                OnAnnouncementChange(new AnnouncementChangeEventArgs(this.announcement));
            }
        }
        public event EventHandler AnnouncementChange;

        protected virtual void OnAnnouncementChange(AnnouncementChangeEventArgs e)
        {
            if (AnnouncementChange != null)
            {
                AnnouncementChange(this, e);
            }
        }
    }
Microsoft Announcement Observer
public class MicrosoftObserver
    {
         
        public MicrosoftObserver(AnnouncementTicker ticker)
        {
            ticker.AnnouncementChange += new EventHandler(bt_BlogChange);
        }

        private void bt_BlogChange(object sender, AnnouncementChangeEventArgs e)
        {
            UpdateDashboard(e.Announcement);
        }

        private void UpdateDashboard(Announcement announcement)
        {
            if (announcement.Company == "0")
            {
                var isNewWindow = true;                 
                MicrosoftDashboard d = ((MicrosoftDashboard)Application.OpenForms["MicrosoftDashboard"]);
                if (d != null && d.Visible == true)
                {
                    isNewWindow = false;
                }               

                d = d ?? new MicrosoftDashboard();
                d.Text = "Microsoft Dashboard";
                var existingContent = d.BlogContent.Text;
                d.BlogContent.Text = string.Format(existingContent + "\n" + announcement.Content);
                if (isNewWindow)
                    d.Show();
            }
        }
        
    }
Google Announcement Observer
public class GoogleObserver
    {
        public GoogleObserver(AnnouncementTicker ticker)
        {
            ticker.AnnouncementChange += new EventHandler(bt_AnnouncementChange);
        }

        private void bt_AnnouncementChange(object sender, AnnouncementChangeEventArgs e)
        {
            UpdateDashboard(e.Announcement);
        }

        private void UpdateDashboard(Announcement announcement)
        {
            if (announcement.Company == "1")
            {
                var isNewWindow = true;
                GoogleDashboard d = ((GoogleDashboard)Application.OpenForms["GoogleDashboard"]);
                if (d != null && d.Visible == true)
                {
                    isNewWindow = false;
                }

                d = d ?? new GoogleDashboard();
                d.Text = "Google Dashboard";
                var existingContent = d.BlogContent.Text;
                d.BlogContent.Text = string.Format(existingContent + "\n" + announcement.Content);
                if (isNewWindow)
                    d.Show();
            }
            
        }

        
    }

Ticker Windows Form
public partial class TIcker : Form
    {
        public TIcker()
        {
            InitializeComponent();
        }

       

        private void button1_Click(object sender, EventArgs e)
        {
            AnnouncementTicker ticker = new AnnouncementTicker();

            MicrosoftObserver msft = new MicrosoftObserver(ticker);
            GoogleObserver ggl = new GoogleObserver(ticker);

            ticker.Announcement = new Announcement { Company = Company.SelectedIndex.ToString(), Content = Content.Text };
               
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            
            Company.Items.Add(new { Name ="Microsoft", Id = 1});
            Company.Items.Add(new { Name = "Google", Id = 2 });
            Company.DisplayMember = "Name";
            Company.ValueMember = "Id";
            Company.SelectedIndex = 0;
        }

        private void Close_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }

Wednesday, July 24, 2013

“ASP.NET_SessionId” cookie in ASP.NET

When a user opens his web browser and makes a request to a ASP.NET Web Application for which a cookie based Session is enabled, Server generates a new SessionId and sends it to web Browser as a cookie with the name "ASP.NET_SessionId". Applications in the same DNS domain share the same Session Id and cookie. When the user browses within the same DNS domain, the browser sends same Session Id and cookie to the domain. Since it is shared across applications in a domain, so ASP.NET doesn't remove the cookie when the session is expired or Session.Abandon() is invoked. Because of this design, the code that is used to check if a Server Session is actually expired doesn't work properly. Generally we use following code snippet to check if session is expired.
if (Session.IsNewSession)
{
   if (Request.Headers("Cookie") != null && Request.Headers("Cookie").IndexOf("ASP.NET_SessionId") >= 0)
   {
        return true;
   }   
}

return false;
As ASP.NET doesn't remove the cookie "ASP.NET_SessionId" when the session is expired, so the above code doesn't check correctly. To ensure the above code works properly, the developer has to manually remove the session cookie in the event of a Session Expiry by using the following code.
Session.Abandon();
Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId") { Expires = DateTime.Now.AddDays(-1d) });
 

Monday, July 22, 2013

Custom Binding Handler in Knockout

demo.html


    
    
    
    
    
    
    



First Name: Last Name:

viewModel.js
function ProfileViewModel() {
    this.profileClosure = ko.observable(false),
    this.firstName = ko.observable("Alex");
    this.lastName = ko.observable("Xaviar");
}

myViewModel = {
    profileVM: ko.observable(),
    initialize: function () {
        myViewModel.profileVM = new ProfileViewModel();
        ko.applyBindings(myViewModel);
    }
    
}
ko-extensions.js
ko.bindingHandlers.closureMode= {
    init: function (element, valueAccessor) {        
        var shouldClose = valueAccessor();
        if (shouldClose) {
            disableAll(element);
        }
        else
            enableAll();
    },
    update: function (element, valueAccessor, allBindingsAccessor) {        
        var shouldClose = valueAccessor();
        var allBindings = allBindingsAccessor();
        var highlight = allBindings.highlight || false;
        if (shouldClose){
            disableAll(element);
        }
        else
            enableAll(element);

        if (shouldClose && highlight) {
            highlightAll(element);
        }
        else
            setToNormal(element);
    }
};

function disableAll(element) {        
    $(element).find('#firstname').attr('disabled', true);
    $(element).find('#lastname').attr('disabled', true);
}

function highlightAll(element) {    
    $(element).find('#firstname').addClass('highlight');
    $(element).find('#lastname').addClass('highlight');
    
}

function enableAll(element) {
    $(element).find('#firstname').attr('disabled', false);
    $(element).find('#lastname').attr('disabled', false);
}

function setToNormal(element) {
    $(element).find('#firstname').removeClass('highlight');
    $(element).find('#lastname').removeClass('highlight');

    $(element).find('#firstname').addClass('normal');
    $(element).find('#lastname').addClass('normal');
}

Sunday, July 21, 2013

HTTP Respons Status Codes

  • 2XX - Request worked
  • 3XX - Resource moved
  • 4xx - Client error
  • 5xx - Server error

Saturday, July 20, 2013

Using KnownType in Serialization

[DataContract]
[KnownType(typeof(Student))]
[KnownType(typeof(Teacher))]
public class Person
{
   [DataMember]
   public string Name{get; set;}
}

//Serialize all derived types of Person.
[DataContract]
[KnownType("GetDerivedTypes")]
public class Person
{
   [DataMember]
   public string Name{get; set;}

   static IEnumerable GetDerivedTypes()
   {
       return from type in typeof(Person).Assembly.GetTypes()
       where typeof(Person).IsAssignableFrom(type)
       select type;
   }
}

[DataContract]
public class Student: Person
{
   [DataMember]
   public string Grade{get; set;}
}

[DataContract]
public class Teacher : Person
{
   [DataMember]
   public string Subject {get; set;}
}

public class MySerializer
{
   var mySerializer = new DataContractSerializer(typeof(Person));
   var stream = new MemoryStream();
   var writter = new XMLTextWritter(stream, Encoding.UTF8) {Formatting = Formatting.Indented};
   mySerializer.WriteObject(writter, new Teacher());
   writter.flush();
   Console.Writeline(stream);
   
}


Thursday, July 18, 2013

RESTful WCF Service

CRUD operations using RESTful WCF Service
    [ServiceContract]
    public interface IBlogService
    {
        [OperationContract]
        [WebInvoke(Method="GET", BodyStyle=WebMessageBodyStyle.Bare, RequestFormat= WebMessageFormat.Json, UriTemplate = "Blog/{id}")]
        BlogPost GetBlogPost(string id);

        [OperationContract]
        [WebInvoke(Method = "GET", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, UriTemplate = "Blog/All")]
        List GetAllPosts();

        [OperationContract]
        [WebInvoke(Method = "POST", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, UriTemplate = "AddBlog/{id}")]
        BlogPost PostBlog(string id, BlogPost post);

        [OperationContract]
        [WebInvoke(Method = "PUT", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, UriTemplate = "UpdateBlog/{id}")]
        void PutBlog(string id, BlogPost post);

        [OperationContract]
        [WebInvoke(Method = "DELETE", BodyStyle = WebMessageBodyStyle.Bare, RequestFormat = WebMessageFormat.Json, UriTemplate = "DeleteBlog/{id}")]
        void DeleteBlog(string id);
    }
    [DataContract]
    public class BlogPost
    {
        [DataMember]
        public string Id { get; set; }
        [DataMember]
        public string Title { get; set; }
        [DataMember]
        public string Content { get; set; }
        [DataMember]
        public string Labels { get; set; }
    }
    
    public class BlogService : IBlogService
    {
        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(string id)
        {
            WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
            return posts.Find(m => m.Id == id);            
        }

        public List GetAllPosts()
        {
            WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
            return posts;
        }

        public BlogPost PostBlog(BlogPost post)
        {
            WebOperationContext.Current.OutgoingResponse.Format = WebMessageFormat.Json;
            posts.Add(post);
            return post;

        }

        public void PutBlog(string id, BlogPost post)
        {
            var blog = posts.Find(m => m.Id == id);
            blog.Title = post.Title;
            blog.Content = post.Content;
        }

        public void DeleteBlog(string id)
        {
            var post = posts.Find(m => m.Id == id);
            posts.Remove(post);
        }
    }


    
      
        
      
    
    
      
        
          
          
          
                  

        
      
      
        
          
        
      
    
    
      
        
      
      

    
  
  
    
    
    
  


    
    
    
    
    


    
My Blogs
    Add Blog
    Title :
    Content:
    Delete Blog

    Wednesday, July 17, 2013

    Javascript Patterns

    Javascript Prototype Pattern

    var TaxCalculator = function(data){
    this.name = data.Name;
    this.basic = data.Basic;
    this.allowances = data.Allowances;
    this.deductions = data.Deductions;
    this.result = 0
    }
    
    TaxCalculator.prototype = {
    CalculateTax: function(){
    this.result = ((this.basic +this.allowances) - this.deductions)*0.1;
    }
    }
    
    
    $(document).ready(function(){
     var data = {Name:Alex, Basic:4000, Allowances:600, Deductions: 400};
     var calc = new TaxCalculator(data);
    calc.CalculateTax();
     alert(calc.result);
    });
    
    
    Overridding a function in prototype pattern
    TaxCalculator.prototype.CalculateTax = function(){
     this.result = ((this.basic +this.allowances) - this.deductions)*0.2;
    }
    
    Namespaces in javascript
    myNamespace = myNamespace || {};
    
    myNamespace.TaxCalculator = function(data){
    this.name = data.Name;
    this.basic = data.Basic;
    this.allowances = data.Allowances;
    this.deductions = data.Deductions;
    this.result = 0
    }
    
    myNamespace.TaxCalculator.prototype = {
    CalculateTax: function(){
    this.result = ((this.basic +this.allowances) - this.deductions)*0.1;
    }
    }
    
    $(document).ready(function(){
     var data = {Name:Alex, Basic:4000, Allowances:600, Deductions: 400};
     var calc = new myNamespace.TaxCalculator(data);
     calc.CalculateTax();
     alert(calc.result);
    });
    
    Module Pattern
    var TaxCalculator = function(data){
       //private members
       var name = data.Name;
       var basic = data.Basic;
       var allowances = data.Allowances;
       var deductions = data.Deductions;
       var result = 0;
    
       return {
          //public members
          CalculateTax : function(){
             result = ((basic + allowances) - deductions)*0.1;
             return result;
          }
       };
    }
    
    $(document).ready(function(){
     var data = {Name:Alex, Basic:4000, Allowances:600, Deductions: 400};
     var calc = new myNamespace.TaxCalculator(data);
     alert(calc.CalculateTax());
     
    });
    
    

    Thursday, June 27, 2013

    How to enforce secure HTTP access to an ASP.NET MVC Application.

    To ensure that your actions are called through only Https, you can decorate your action methods with RequireHttps attribute. But this will not work in your development server as usually the development box is not configured with HTTPS. Basically you need to to apply this attribute conditionally based on a configurable item. This can be achieved by creating a custom class that is derived from RequireHttpsAttribute and by overridding its OnAuthorization().

    
    using System;
    using System.Configuration;
    using System.Web;
    using System.Web.Mvc;
    
    public class RequireSslAttribute : RequireHttpsAttribute
        {
            private const string EnableSslKey = "EnableSSLForMySite";
    
            public override void OnAuthorization(AuthorizationContext filterContext)
            {
                if (filterContext == null)
                {
                    throw new ArgumentException("filterContext");
                }
    
                if (!IsHttpContextNull(filterContext) && !IsEnableSsl())
                {
                    return;
                }
    
                BaseOnAuthorization(filterContext);
            }
    
            protected virtual void BaseOnAuthorization(AuthorizationContext filterContext)
            {
                base.OnAuthorization(filterContext);
            }
    
            protected virtual bool IsHttpContextNull(AuthorizationContext filterContext)
            {
                return filterContext.HttpContext == null;
            }
    
            protected virtual bool IsEnableSsl()
            {
                var enableSslForMySite = HttpRuntime.Cache.Get(EnableSslKey);
                bool isEnableSsl = false;
    
                if (enableSslForMySite == null)
                {
                    string configEnableSsl = ConfigurationManager.AppSettings[EnableSslKey] ?? string.Empty;
    
                    isEnableSsl = (configEnableSsl.ToLower() == "true");
                    HttpRuntime.Cache.Insert(EnableSslKey, isEnableSsl);
                }
                else
                {
                    bool.TryParse(enableSsl.ToString(), out isEnableSsl);
                }
    
                return isEnableSsl;
            }
        }
    BaseController
    
        [RequireSsl]
        public abstract class BaseController : Controller
        {
        }
    

    Tuesday, June 25, 2013

    How to track Browser's Back button to prevent user to visit an already deleted entity.


    Solutions:

    There are 2 ways by which the user can come back to a deleted entity. 1. By typing the Url in the browser address bar. 2. By clicking on the browser back button just after deleting the entity. While option-1 is already taken care of by redirecting the user to an Add New screen but the second option certainly allows the user to update an entity that is already deleted. So the solutions described here are applicable for option-2 scenario.

    Solution – 1: By tracking a deleted flag using a Hidden Field.

    The value of a hidden field is retained when you use the browser back/Forward button. So the value of a hidden field can be used to check if the user has clicked the browser back button to reach the current page.

    The solution can be implemented by following three simple steps.

    1. A hidden field with default value “0” is added to all UI which provides the provision to delete an entity. This doesn’t work if we add it programmatically. It has to be added in the .cshtml file.
    2. Inside the success callback of the delete method, set the value of the hidden field to “1”.
    3. On document load, check the value of the hidden field. If it is “1” then the current entity is a deleted entity.

    Solution – 2: Using History.js

    The idea here to use HTML5 History/State API (pushState, getState etc.) to modify the history entries by replacing the current state with a delete state after a delete operation is over. pustState() & replaceState(0 are the two methods used to add/modify the history entries. This changes the referrer that gets used in the HTTP Header for XMLHttpRequest object. Then use the HTML5 onhaschange event to check if the current state of the entity matches with any of the previous deleted state in the History.

    During this research it is established that Internet Explorer version 9 or less doesn’t supports HTML5 History/State API. Further research on this lead us to History.js plug-in which gracefully supports HTML5 History/State API in all browsers including the browsers that don’t support HTML5. So the POC is done based on the same idea using the History.js.

    Here are the steps to implement this solution.

    1. Add code to modify the history entry of the current state with a deleted state inside the success callback of the delete Ajax call.
    2. Bind a custom function to the statechange event to check if the current state matches with any previous deleted state in history. If a match is found then take necessary action to alert the user about it.

    Conclusions:

    Based on the ease of development, it seems that Hidden Field approach is the best option available currently with only additional burden of adding a hidden field on all UI that provides the provision to delete an entity except search screens.

    Resources:

    http://msdn.microsoft.com/en-us/magazine/ff690558.aspx http://benalman.com/code/projects/jquery-hashchange/examples/hashchange/ https://github.com/browserstate/history.js


    Altering a SQL Table on Production


    Altering a SQL Table to add a column on Production can be risky affair as it contains vital production data in it. The sql script given below gives an idea how to go for it. In the example below, the table is getting altered to add the new column [Column6].
    
    USE <>
    GO
    
    BEGIN TRANSACTION
    SET QUOTED_IDENTIFIER ON
    SET ARITHABORT ON
    SET NUMERIC_ROUNDABORT OFF
    SET CONCAT_NULL_YIELDS_NULL ON
    SET ANSI_NULLS ON
    SET ANSI_PADDING ON
    SET ANSI_WARNINGS ON
    COMMIT
    
    BEGIN TRANSACTION
    GO
    CREATE TABLE dbo.Tmp_
    	(
    	[Key] [int] IDENTITY(1,1) NOT NULL,
    	[Column1] [int] NOT NULL,
    	[Column2] [int] NOT NULL,
    	[Column3] [int] NULL,
    	[Column4] [int] NOT NULL,
    	[Column5] [varchar](50) NULL,
    	[Column6] [int] NULL	
    	)  ON [PRIMARY]
    GO
    ALTER TABLE dbo.Tmp_TableName SET (LOCK_ESCALATION = TABLE)
    GO
    SET IDENTITY_INSERT dbo.Tmp_TableName ON
    GO
    IF EXISTS(SELECT * FROM dbo.TableName)
    	 EXEC('INSERT INTO dbo.Tmp_TableName ([Key],[Column1], [Column2],[Column3], [Column4], [Column5])
    		SELECT [Key],[Column1], [Column2],[Column3], [Column4], [Column5] FROM dbo.TableName WITH (HOLDLOCK TABLOCKX)')
    GO
    SET IDENTITY_INSERT dbo.Tmp_TableName OFF
    GO
    
    DROP TABLE dbo.TableName
    GO
    EXECUTE sp_rename N'dbo.Tmp_TableName', N'TableName', 'OBJECT' 
    GO
    ALTER TABLE dbo.TableName ADD CONSTRAINT
    	PK_TableName PRIMARY KEY CLUSTERED 
    	(
    	[Key]
    	) WITH( STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    
    GO
    
    ALTER TABLE [dbo].[TableName]  WITH CHECK ADD  CONSTRAINT [FK_TableName_FKTable1] FOREIGN KEY([Column1])
    REFERENCES [dbo].[FKTable1] ([Key])
    GO
    
    ALTER TABLE [dbo].[TableName]  WITH CHECK ADD  CONSTRAINT [FK_TableName_FKTable2] FOREIGN KEY([Column2])
    REFERENCES [dbo].[FKTable2] ([Key])
    GO
    
    ALTER TABLE [dbo].[TableName]  WITH CHECK ADD  CONSTRAINT [FK_TableName_FKTable3] FOREIGN KEY([Column3])
    REFERENCES [dbo].[FKTable3] ([Key])
    GO
    
    ALTER TABLE [dbo].[TableName]  WITH CHECK ADD  CONSTRAINT [FK_TableName_FKTable14] FOREIGN KEY([Column4])
    REFERENCES [dbo].[FKTable4] ([Key])
    GO
    
    ALTER TABLE [dbo].[TableName]  WITH CHECK ADD  CONSTRAINT [FK_TableName_Table5] FOREIGN KEY([Column5])
    REFERENCES [dbo].[FKTable5] ([Key])
    GO
    
    
    COMMIT
    
    
    

    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.