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

References:

 

https://social.technet.microsoft.com/Forums/scriptcenter/en-US/0a01e7e1-babf-44d0-9b3a-6d0916a5e6b7/uninstall-sql-2008-r2-with-powershell?forum=ITCG

http://windowsitpro.com/scripting/auditing-32-bit-and-64-bit-applications-powershell

http://sqlblog.com/blogs/rob_farley/archive/2011/05/24/powershell-script-to-help-uninstall-sql-server-2008-r2-evaluation-edition.aspx

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

 [Serializable]
    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());

References:

http://stackoverflow.com/questions/12795882/quickest-way-to-compare-two-list
http://stackoverflow.com/questions/188141/list-orderby-alphabetical-order

Call ASP.Net Page Method using jQuery AJAX Example

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

<!DOCTYPE html>

<script runat="server">

    [System.Web.Services.WebMethod]
    public static string GetCurrentTime(string name)
    {        
        return "Hello " + name + Environment.NewLine + "The Current Time is: "
            + DateTime.Now.ToString();
        
    }

</script>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
        <script src="Scripts/jquery-2.1.3.min.js" type="text/javascript"></script>
        <script type="text/javascript">
            function ShowCurrentTime() {
                $.ajax({
                    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) {
                         alert(response.d);
                     }
                 });
             }
             function OnSuccess(response) {
                 //alert(response.d);
                 $("#DivShowAfterClick").append("<p>" + response.d + "</p>");
                 $("#DivShowAfterClick").toggle();                
             }
        </script>

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

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

    </form>
</body>
</html>

Source: http://aspsnippets.com/Articles/Call-ASPNet-Page-Method-using-jQuery-AJAX-Example.aspx

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())
            {
                try
                {
                    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!
                                    </div>
 <asp:HiddenField ID="hdnLoginFormState" runat="Server" Value="0" />
                    <script>
                        // Retain Login Form expansion/contraction state between postbacks
                        $(document).ready(function () {
                            var hdnState = $('#<%=hdnLoginFormState.ClientID %>').val();
                             if (hdnState == "0") {
                                 $("[id$='DivLoginForm']").hide();
                             }
                             else {
                                 $("[id$='DivLoginForm']").show();
                             }

                             $('a#aLoginForStreamlined').click(function () {
                                 $("[id$='DivLoginForm']").toggle();

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

                             });
                         });

                    </script>

How To Easily Add Log4Net To Your .NET Project

  1. Download Log4Net binaries –>  http://logging.apache.org/log4net/download_log4net.cgi
  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
            log4net.Config.XmlConfigurator.Configure();        
    
        }
        
    
  5. Add Log4Net config section and declaration into web.config/app.config
    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
      <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
      </configSections>
      <appSettings>   
      </appSettings>
      <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 "/>
          </layout>
        </appender>
        <root>
          <level value="DEBUG"/>
          <appender-ref ref="LogFileAppender"/>
        </root>
      </log4net>
    </configuration>
    
  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="http://www.w3.org/1999/xhtml">
<head runat="server">
  <title>ASP.NET Diagnostic Page</title>
</head>
<body>
  <form id="form1" runat="server">
  
  <h2>Environment Variables</h2>
  <pre>
  <table>  
<%
    var variables = Environment.GetEnvironmentVariables();
    foreach (DictionaryEntry entry in variables)
    {
      Response.Write("<tr><td>");
      Response.Write(entry.Key);
      Response.Write("</td><td>");
      Response.Write(entry.Value);
      Response.Write("</td></tr>");
    }
  %>
  </table>
  </pre>

  <h2>Misc</h2>
  <pre>
  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])) %>
  </pre>
  
  </form>
</body>
</html>

Source: http://www.codeproject.com/Articles/229356/ASP-NET-Diagnostic-page-to-dump-ASP-NET-and-Enviro