Blog Moved....

I have moved to WordPress as a part of my quest to move away from Google! Please go to http://seanpj.wordpress.com to view my new blog.

Vault/Fortress Diff & Merge Error

After a painful re-image of my laptop I resumed my daily web development work only to realize that for some reason the connection to my vault diff & merge tool had been broken.  With a not-so-useful error I was able to hunt down the problem to an incorrectly mapped executable due to bogus environment variables being used.  I believe this is an error with Vault in the installation. 

If you go to Visual Studio Options > Source Control > Vault (or Fortress) Options > Advanced Options > Diff/Merge.  Look for the paths to the Diff/Merge EXE.  Browse to the file SGDM.EXE using the browse button, click OK.  You do not need to restart VS to complete this fix.

SQL 2008 R2 Install Issue... SQL 2005 Tools Still Installed?

When installing SQL 2008 R2 November CTP I received the following error:

"The SQL Server 2005 Express Tools are installed. To continue, remove the SQL Server 2005 Express Tools."

I checked add/remove, I checked the "Program Files" directory, but could not find a trace of the SQL 2005 Express Tools installed.

After a little research I found this posting: http://sqlblogcasts.com/blogs/sqldbatips/archive/2008/08/14/sql-2008-install-blocked-on-express-tools-but-actually-due-to-sql-prompt.aspx

Jasper mentions that older versions of RedGate SQL Prompt can cause this issue. You can find that by digging through the registry and looking for dependencies. In addition to the issue with SQL Prompt (only version 3 and below) there is an issue with the newer version of RedGate SQL Search. I uninstalled boh and SQL 2008 R2 installed fine.

Last Post for Tonight…. maybe

As I was doing a little development tonight I realized that I was using one of the new features of VS2010 and totally forgot it was new.  Some multi-line editing features make what used to be a pain a now simple process:

Optional & Named Parameters in C# 4.0

I have to say this is one of my favorite features added to this new version.  I don’t know how many times I have gone into method overload madness because C# has never supported optional parameters.  VB.Net always has…why not C#?  Well, now it does!

public void AddUser(string firstName, string lastName, string status = "New User") {
  User = new User(firstName, lastName, status);
}


Now this method could be called in a few ways:



AddUser("Sean", "Jaeger", "Working right now");
AddUser("Sean", "Jaeger");
AddUser(lastName: "Jaeger", firstName: "Sean");


Pretty darn  cool!

SQL 2008 / SQL 2008 R2 Frustration

Since I have now run into this issue 3 times and each time had to look it up to find out to fix it, I decided to post about it.  If you use SSMS 2008/2008 R2 you will find out very quickly that altering a table using the GUI will throw an error.  This is because SQL has added a new “feature” to prevent us from doing this.

In order to turn this “feature” off you will need to go to tools > options.  On this screen uncheck this option:

SQL 2008 Prevent Table Saves

I do not think this is a bad “feature”, but it should be something that admins can set at the server level to prevent it in UAT/Production environments… makes little sense in a development environment.

Tuple Type Added to C# 4.0

With C# 4.0 you can now use the new Tuple type instead of creating your very own… far simpler than using a struct or class to accomplish the same task.

There are two ways to create a Tuple in c# 4.0:

var newTuple = new Tuple<string, string, int>("Sean", "Jaeger", 36);
var newTuple = Tuple.Create<string, string, int>("Sean", "Jaeger", 36);


Type inference can also be used (but doesn’t self document):



var newTuple = new Tuple.Create("Sean", "Jaeger", 36);


You can add up to eight parameters now:



var newTuple = new Tuple<int, int, int, int, int, int, int, int>(1, 2, 3, 4, 5, 6, 7, 8);


One huge thing I see in using a Tuple rather than an anonymous type is the fact that scope can be at any level.  As we all know the scope of an anonymous type is limited to the method boundaries.



Fun stuff!

HtmlEncode() Without The HtmlEncode()

<script runat="server" language="c#">
  protected string BadHtml = "<script language='javascript'>alert('Hello');</script>";
</script>
<%=BadHtml%>


The code above would cause an alert box to pop saying “Hello” because it is not HTML encoded.  Typically what you might do here is use the Server.HtmlEncode() method within a property and use that instead.  But now with C# 4.0 & Visual Studio 2010 you can just write this:



<script runat="server" language="c#">
    protected string BadHtml = "<script language='javascript'>alert('Hello');</script>";
</script>
<%:BadHtml%>


Notice the “:” instead of “=”.  This will automatically do the encode for you.  Saving keystrokes is great!