LessThanDot Site Logo

LessThanDot

A decade of helpful technical content

This is an archive of the posts published to LessThanDot from 2008 to 2018, over a decade of useful content. While we're no longer adding new content, we still receive a lot of visitors and wanted to make sure the content didn't disappear forever.

Not as anonymous as you thought you were...

I was reading an editorial by Jeff Pearlman who is a sports writer for Sports Illustrated and his article resonated with me – which is not to say that I have experienced his problem, per se, but that I have certainly noticed it as an issue as I peruse various other sites and forums. Essentially, he detailed his experiences with a couple of exceedingly rude internet users (trolls, for lack of a better term) and how they were when they believed they were anonymous and then how they became when he tracked them down.

Read More...

Product Selection, Requirements and Scoring

Product Selection: 1: Identifying Needs 2: Requirements and Scoring 3: Evaluation 4: Review Once we have the purpose of the product selection defined, it’s time to move on to defining the characteristics we need or want from our product. Up until this point in the process we have talked to people one-on-one or in small groups. Now that we have identified the core need or needs the product must fulfill, we are ready to expand that into the list of requirements and features by incorporating input from the wider group of affected people. We can use brainstorming to engage people as well as help them voice their expectations and evaluate the relative priorities of those expectations.

Read More...

Collection and array initializers in VB.Net and the difference with C#

Ok I admit VB.Net is a weird language and one wonders where the designers got their inspiration from. Let’s see how we can initialize an array while letting the compiler infer the type. In C# that would be. var stringarray = new[] { "test", "test" };``` In VB.Net this is. ```vbnet Dim stringarray = {"test", "test"}``` Which might be slightly better and shorter than the C# version. Now lets see the syntax for when we want to specify the type. In C#. ```csharp var stringarray = new string[] {"test", "test"};``` And in VB.Net that will be. ```vbnet Dim stringarray = New String() {"test", "test"}``` Both are ok. Now lets look at the collection initializers like list. In C#. ```csharp var stringlist = new List<string> {"test", "test"};``` In VB.Net. ```vbnet Dim stringlist = New List(Of String) From {"test", "test"}``` The thing that strikes me as odd here is that someone decided they needed the From keyword here to make it work. So to recap. C# ```csharp var stringarray = new[] { "test", "test" }; var stringarray = new string[] {"test", "test"}; var stringlist = new List<string> {"test", "test"};``` VB.Net ```vbnet Dim stringarray = {"test", "test"} Dim stringarray = New String() {"test", "test"} Dim stringlist = New List(Of String) From {"test", "test"}``` I think the C# version is much more consistent than the VB version so it would be nice if someone fixed that in the next version, thank you in advance ;-).

Read More...

Twitter – I do want to follow you but...

I think Twitter is a valued resource and I take it seriously when telling other professionals that they should be utilizing it. At times, the day requires the comedy and relaxing feel that we can get from people that understand the work that we do day in and day out. Other times such resources like the SQLHELP hash tag are absolutely crucial to problems that need several minds turning in order to resolve problems quickly. Other great uses are things such as marketing your blogs, books, magazine publications and even promotions or career changes, opportunities…there really is no end to it.

Read More...

Renaming Physical Database Files

Using ALTER DATABASE and MODIFY FILE you can reset the metadata in the master database for renaming physical mdf and ldf files. This however does not actually change the physical file name itself on disk. To fix that, you are typically required to change the metadata in master and then manually change the physical files on disk after taking the database offline. Then bring the database online and the task is complete.

Read More...

Making an XMLLayout for Log4Net with an xsl file to make it human readable.

In one of my [previous posts][1] where I made an HTMLLayout for Log4Net Wim ten Brink commented that I should use XML with xsl instead. AS I always listen to my followers. I did so swiftly. Here is the XslLayout class I created, Yes I know that there is an XMLLayout class available but that isn’t as good as the one I have. Imports log4net.Layout Imports System.Text Namespace Logging.FileLog Public Class XslLayout Inherits LayoutSkeleton Public Overrides Sub ActivateOptions() End Sub Public Overrides Sub Format(ByVal writer As System.IO.TextWriter, ByVal loggingEvent As log4net.Core.LoggingEvent) If loggingEvent Is Nothing Then Throw New ArgumentNullException("loggingEvent") End If writer.Write("&lt;log&gt;") writer.Write("&lt;datetime&gt;" & DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") & "&lt;/datetime&gt;") writer.Write("&lt;thread&gt;" & loggingEvent.ThreadName & "&lt;/thread&gt;") writer.Write("&lt;level&gt;" & loggingEvent.Level.DisplayName & "&lt;/level&gt;") If loggingEvent.ExceptionObject IsNot Nothing Then writer.Write("&lt;class&gt;" & loggingEvent.ExceptionObject.Source & "&lt;/class&gt;") Else writer.Write("&lt;class&gt;?&lt;/class&gt;") End If writer.Write("&lt;message&gt;") loggingEvent.WriteRenderedMessage(writer) writer.Write("&lt;/message&gt;") writer.Write("&lt;/log&gt;") writer.WriteLine() End Sub Public Overrides Property Header As String Get Dim _Header As New StringBuilder _Header.Append("&lt;?xml version=""1.0"" encoding=""utf-8""?&gt;") _Header.Append("&lt;?xml-stylesheet href=""log.xsl"" type=""text/xsl""?&gt;") _Header.Append("&lt;logs&gt;") _Header.Append("&lt;header&gt;Started logging at " & DateTime.Now & "&lt;/header&gt;") Return _Header.ToString End Get Set(ByVal value As String) MyBase.Header = value End Set End Property Public Overrides Property Footer As String Get Dim _Footer As New StringBuilder _Footer.Append("&lt;footer&gt;Stopped logging at " & DateTime.Now & "&lt;/footer&gt;") _Footer.Append("&lt;/logs&gt;") Return _Footer.ToString End Get Set(ByVal value As String) MyBase.Footer = value End Set End Property End Class End Namespace``` and this is the xsl file to go with it. ```xml &lt;?xml version="1.0"?&gt; &lt;xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"&gt; &lt;xsl:template match="/"&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;LogFile&lt;/title&gt; &lt;style type="text/css"&gt; table, th, td{ border: 1px solid black;} table {border-collapse:collapse;width:100%;} th{background-color:gray; color:white;} .warn{color:red;} .info{color:green;} .alternatecolor{background-color:lightCyan;} &lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;p&gt; &lt;xsl:value-of select="logs/header"/&gt; &lt;/p&gt; &lt;table&gt; &lt;tr&gt; &lt;th&gt;Date time&lt;/th&gt; &lt;th&gt;Thread&lt;/th&gt; &lt;th&gt;Level&lt;/th&gt; &lt;th&gt;Class&lt;/th&gt; &lt;th&gt;Message&lt;/th&gt; &lt;/tr&gt; &lt;xsl:for-each select="logs/log"&gt; &lt;tr&gt; &lt;xsl:if test="position() mod 2 = 1"&gt; &lt;xsl:attribute name="class"&gt; &lt;xsl:value-of select="translate(level, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ', 'abcdefghijklmnopqrstuvwxyz_')"/&gt; &lt;/xsl:attribute&gt; &lt;/xsl:if&gt; &lt;xsl:if test="position() mod 2 = 0"&gt; &lt;xsl:attribute name="class"&gt; &lt;xsl:value-of select="translate(level, 'ABCDEFGHIJKLMNOPQRSTUVWXYZ ', 'abcdefghijklmnopqrstuvwxyz_')"/&gt; alternatecolor &lt;/xsl:attribute&gt; &lt;/xsl:if&gt; &lt;td&gt; &lt;xsl:value-of select="datetime"/&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="level"/&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="thread"/&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="class"/&gt; &lt;/td&gt; &lt;td&gt; &lt;xsl:value-of select="message"/&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/xsl:for-each&gt; &lt;/table&gt; &lt;p&gt; &lt;xsl:value-of select="logs/footer"/&gt; &lt;/p&gt; &lt;hr /&gt; &lt;/body&gt; &lt;/html&gt; &lt;/xsl:template&gt; &lt;/xsl:stylesheet&gt;``` That was fun. And here the result. The XML logfile. ```xml &lt;?xml version="1.0" encoding="utf-8"?&gt;&lt;?xml-stylesheet href="log.xsl" type="text/xsl"?&gt;&lt;logs&gt;&lt;header&gt;Started logging at 9/02/2011 14:27:11&lt;/header&gt;&lt;log&gt;&lt;datetime&gt;2011-02-09 14:27:16&lt;/datetime&gt;&lt;thread&gt;10&lt;/thread&gt;&lt;level&gt;INFO&lt;/level&gt;&lt;class&gt;?&lt;/class&gt;&lt;message&gt;Using NHibernateConfiguration. Database: Server: &lt;/message&gt;&lt;/log&gt; &lt;log&gt;&lt;datetime&gt;2011-02-09 14:27:18&lt;/datetime&gt;&lt;thread&gt;10&lt;/thread&gt;&lt;level&gt;DEBUG&lt;/level&gt;&lt;class&gt;?&lt;/class&gt;&lt;message&gt;Constructor - Log initialized&lt;/message&gt;&lt;/log&gt; &lt;log&gt;&lt;datetime&gt;2011-02-09 14:27:19&lt;/datetime&gt;&lt;thread&gt;10&lt;/thread&gt;&lt;level&gt;WARN&lt;/level&gt;&lt;class&gt;?&lt;/class&gt;&lt;message&gt;Is this warning on?&lt;/message&gt;&lt;/log&gt; &lt;log&gt;&lt;datetime&gt;2011-02-09 14:27:19&lt;/datetime&gt;&lt;thread&gt;10&lt;/thread&gt;&lt;level&gt;DEBUG&lt;/level&gt;&lt;class&gt;?&lt;/class&gt;&lt;message&gt;Is this debug on?&lt;/message&gt;&lt;/log&gt; &lt;log&gt;&lt;datetime&gt;2011-02-09 14:27:19&lt;/datetime&gt;&lt;thread&gt;10&lt;/thread&gt;&lt;level&gt;INFO&lt;/level&gt;&lt;class&gt;?&lt;/class&gt;&lt;message&gt;Is this info on?&lt;/message&gt;&lt;/log&gt; &lt;footer&gt;Stopped logging at 9/02/2011 14:27:22&lt;/footer&gt;&lt;/logs&gt;``` And the result in the browser. <div class="image_block"> <a href="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/log4net/log4net2.png?mtime=1297245330"><img alt="" src="https://lessthandot.z19.web.core.windows.net/wp-content/uploads/users/chrissie1/log4net/log4net2.png?mtime=1297245330" width="1006" height="287" /></a> </div> That looks exactly the same as previous and the resulting logfile is machinereadable to boot. <span class="MT_red">Warning: Your appender should have the AppendToFile attribute set to False else this will generate invalid XML. That is also the biggest drawback of this method. You could of course just create invalid XML and then write a parser but that was not really the point of the exercise.</p> <p> Warnign 2: You also want to write the xsl to where the log file has been written else the result will be less satisfying.</span> </p> [1]: /index.php/DesktopDev/MSTech/why-do-you-make-unreadable

Read More...

Find NoLock in an sql statement and remove it.

My fellow blogger Ted Kreuger posted [this powershell thing][1] where he wants to remove the NOLOCk keyword from a statement (I have no idea why but he must have a good reason). So I commented that he could perhaps have done it with linq instead of regex. I was mistaken linq has nothing to do with this. Regex is evil. So I set up a testcase, I didn’t feel like doing it in but in csharp, just for fun.

Read More...

Why do you make unreadable logfiles?

Why do you make unreadable logfiles? I was talking to myself there, me and myself tend to have such conversations a lot lately. Anyway, we digress. I used to have some simple output for my logfiles. [Header started logging at 3/02/2011 13:20:38] 2011-02-03 13:20:48,003 [1] WARN Logger [TDB2009.View.Menu.Winforms.Startup.StartUp] - Is this warning on? [footer] If you put that in debugging mode you will end up with a lot of files and not much of it will be readable. Finding the warns will be difficult at best.

Read More...

How To Unpivot (and pivot) Like a Boss

Pivoting and Unpivoting data has been one of the parts of tsql that has been eluding my grasp for a while now. I’ve seen plenty of examples for both of these, but none of those examples really helped me in understanding exactly what’s going on. We have a wiki article for each here on LTD, Pivot and Unpivot, but again these don’t tell me a whole lot about what’s going on, just the before and after pictures. Well, I was messing around with the unpivot code the other day, and how it worked finally dawned on me. So, I would like to share what I learned.

Read More...

T-SQL Tuesday#15 – Automation with PowerShell (Replace with RegEx)

The big man with the camera, Pat Wright (Blog | Twitter) is holding T-SQL Tuesday this month. The topic this month is Automation with T-SQL or with PowerShell (or a mix of both). Most know that when I say automation, SSIS is the first thing to come to mind. I’ve taken SSIS and abused and tuned it to automate just about every DBA task that is known to SQL Server. I’ve started to take my own advice over the last year though. I’ve taken PowerShell to heart on how rapidly you can write, execute and automate scripts to handle some of my SSIS packages. The ultimate goal is always to spend less time writing these automation initiatives and getting them in place so they are working for us.

Read More...