How To Completely Uninstall/Remove All Versions of SQL Server and related tools/docs

  1. Download get-installedapp.ps1
  2. Load PowerShell ISE and execute the following:
    .\get-installedapp -appname "*SQL*SERVER*" -matchall |  select-object -expandproperty AppID |   foreach-object { "msiexec /x ""$_""" } > uninstall.bat
  3. Run the generated uninstall.bat


To see what applications the above command would remove, run this first:

.\get-installedapp -appname "*SQL*SERVER*" -matchall  | select-object AppName,AppID


How To Compare 2 Lists Determining If A Property Has Changed, Ignoring Order

In the list you want to perform the comparison against, override Equals

    public class AlertSubscriptionOption
  /// <summary>
        /// Determines whether the specified <see cref="System.Object" />, is equal to this instance.
        /// </summary>
        /// <param name="obj">The <see cref="System.Object" /> to compare with this instance.</param>
        /// <returns>
        ///   <c>true</c> if the specified <see cref="System.Object" /> is equal to this instance; otherwise, <c>false</c>.
        /// </returns>
        public override bool Equals(object obj)
            // Check for null values and compare run-time types.
            if (obj == null || GetType() != obj.GetType())
                return false;

            AlertSubscriptionOption p = (AlertSubscriptionOption)obj;
            return this.SubType == p.SubType;

Now, to compare the 2 lists, perform the following

     bool subscriptionEmailDifferent = false;
    subscriptionEmailDifferent = (newSubscriptionEmailOptions.Count > 0 || oldSubscriptionEmailOptions.Count > 0) &&
                                          !newSubscriptionEmailOptions.OrderBy(x => x.SubType).ToList().SequenceEqual(oldSubscriptionEmailOptions.OrderBy(x => x.SubType).ToList());


Call ASP.Net Page Method using jQuery AJAX Example

<%@ Page Language="C#" %>

<!DOCTYPE html>

<script runat="server">

    public static string GetCurrentTime(string name)
        return "Hello " + name + Environment.NewLine + "The Current Time is: "
            + DateTime.Now.ToString();


<html xmlns="">
<head runat="server">
    <form id="form1" runat="server">
        <script src="Scripts/jquery-2.1.3.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function ShowCurrentTime() {
                    type: "POST",
                    url: "Default.aspx/GetCurrentTime",
                    data: '{name: "' + $("#<%=txtUserName.ClientID%>")[0].value + '" }',
                     contentType: "application/json; charset=utf-8",
                     dataType: "json",
                     success: OnSuccess,
                     failure: function (response) {
             function OnSuccess(response) {
                 $("#DivShowAfterClick").append("<p>" + response.d + "</p>");

            Your Name :
            <asp:TextBox ID="txtUserName" runat="server"></asp:TextBox>
            <input id="btnGetTime" type="button" value="Show Current Time"
                onclick="ShowCurrentTime()" />

        <div id="DivShowAfterClick" runat="server">This should be invisible until button clicked.</div>



Clean And Simple Way To Log Entire Contents/Properties Of C# Objects

        /// <summary>
        /// Objects to XML.
        /// </summary>
        /// <param name="output">The output.</param>
        /// <returns></returns>
        public static string ObjectToXml(object output)
            string objectAsXmlString;

            System.Xml.Serialization.XmlSerializer xs = new System.Xml.Serialization.XmlSerializer(output.GetType());
            using (System.IO.StringWriter sw = new System.IO.StringWriter())
                    xs.Serialize(sw, output);
                    objectAsXmlString = sw.ToString();
                catch (Exception ex)
                    objectAsXmlString = ex.ToString();

            return objectAsXmlString;

How To Easily Preserve State Of DIV (Hide/Show) Between Post-backs In ASP.NET with JavaScript

                          <p>Already have an online account? <a href="#" id="aLoginForStreamlined">Log in for a streamlined experience</a>.</p>

<div id="DivLoginForm" style="display: none">
                                       Content To Hide/Show Here!
 <asp:HiddenField ID="hdnLoginFormState" runat="Server" Value="0" />
                        // Retain Login Form expansion/contraction state between postbacks
                        $(document).ready(function () {
                            var hdnState = $('#<%=hdnLoginFormState.ClientID %>').val();
                             if (hdnState == "0") {
                             else {

                             $('a#aLoginForStreamlined').click(function () {

                                 var oldValue = $('#<%=hdnLoginFormState.ClientID %>').val();
                                 var newValue = (oldValue == 0) ? "1" : "0";
                                 $('#<%=hdnLoginFormState.ClientID %>').val(newValue);
                                 return false;



How To Easily Add Log4Net To Your .NET Project

  1. Download Log4Net binaries –>
  2. Add Reference to Log4Net.dll in your project
  3. Create new “Logs” folder and ensure Web App/Site has Write privileges to this directory
  4. Add the following to Global.asmx
        /// &lt;summary&gt;
        /// Gets the application log4net log instance.
        /// &lt;/summary&gt;
        /// &lt;value&gt;The log.&lt;/value&gt;
        public ILog log
            get { return LogManager.GetLogger(&quot;AppLogger&quot;); }
        void Application_Start(object sender, EventArgs e) 
            // Code that runs on application startup
  5. Add Log4Net config section and declaration into web.config/app.config
    <?xml version="1.0" encoding="utf-8" ?>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        <appender name="LogFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="Logs/application.log"/>
          <appendToFile value="true"/>
          <rollingStyle value="Composite"/>
          <datePattern value="yyyyMMdd"/>
          <maxSizeRollBackups value="10"/>
          <maximumFileSize value="5MB"/>
          <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
          <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%n DATE: %date{MM/dd/yyyy HH:mm:ss} %n THREAD: [%thread] %n LEVEL: %-5level %n USER ID: %identity %n CLASS: %type{1} %n METHOD: %M %n LOCATION: %location %n MESSAGE: %message %n "/>
          <level value="DEBUG"/>
          <appender-ref ref="LogFileAppender"/>
  6. Add private static readonly property referencing ILog
      class Program
            /// &lt;summary&gt;
            /// Logging
            /// &lt;/summary&gt;
            //private readonly ILog Logger = DecisionLogManager.GetLogger(typeof(UC4Request));    
          private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
  7. Call Error method to log error
                catch (Exception ex)
                    // Log to local log file
                    log.Error("Error", ex);
  8. You can also call other methods (Info) to output debug information
             log.Info(responseOutput +
                             Environment.NewLine +
                             Base.HelperFunctions.ObjectToString(keywordClientReply, DisplayMode.HTML)

ASP.NET Diagnostic Page to Dump ASP.NET and Environment Configuration

<%@ Page Language="C#" AutoEventWireup="true" Trace="true" TraceMode="SortByCategory" %>
<html xmlns="">
<head runat="server">
  <title>ASP.NET Diagnostic Page</title>
  <form id="form1" runat="server">
  <h2>Environment Variables</h2>
    var variables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry entry in variables)

  Response.Filter = <%= Request.Filter.ToString() %>
  Request.ApplicationPath = <%= Request.ApplicationPath %>
  Request.PhysicalApplicationPath = <%= Request.PhysicalApplicationPath %>
  Request.PhysicalPath = <%= Request.PhysicalPath %>
  Request.UrlReferrer = <%= Request.UrlReferrer %>
  Request.UserLanguages = <%= string.Join(",", (Request.UserLanguages ?? new string[0])) %>


How to Re-Enable Create Unit Tests Context Menu In Visual Studio 2012

To re-enable the Create Unit Tests… menu, go to Tools->Customize… to launch the Customize dialog. At the Customize dialog, go to the Commands tab, select the Context menu radio button and choose Editor Context Menus | Code Window.

You will realized that the menu item is actually available in the context menu. 🙂 The VS developers were kind enough to leave it there for us. *HeHe* Click on the Create Unit Tests… menu item and click either Move Up or Move Down. [Note: My screenshot is showing Create Unit Test in singular because I had previously tried to rename it]. Then click Close.

Restart Visual Studio 2012 and whalla! The context menu will be available!

Note: This apparently does not work in Visual Studio 2013.
Alternative is to use this Visual Studio Extension: Unit Test Generator