Tuesday, November 13, 2012

How to Uninstall CollabNet Desktop Version

What is CollabNet?
CollabNet is a site that has a lot of nice almost free tools for you to use in a variety of places. I happen to use AnkSVN which is a plug in for Visual Studio that allows you to use the Pending Changes window to submit (check-in) recent changes and notes directly into your SVN instance. CollabNet also has their own Subversion (SVN) instance which I have been using at home and it is very nice. All of this stuff is free if you sign up for an account and basically deal with the spam that you get from them in your inbox. Not a big deal.

There is one program in particular that I don't use called CollabNet Desktop, there is nothing wrong with it I just don't need to use it.

The Gotcha
I had CollabNet Desktop Version installed and I couldn't uninstall it. I tried using the regular old "Control Panel\Programs\Programs and Features" to try to uninstall it and it didn't show up in the list. I wanted to just delete the files (which isn't a good idea), but I wasn't too sure where they were living because I use AnkSVN too, so I didn't want to damage that installation. Visual Studio didn't have any way to disable it or uninstall it either. What do you do now?

The Work Around (Fix?)
This is going to sound stupid but:

  1. Install the latest version
  2. Then uninstall what you just installed

I have done this before for similar situations. This will usually work because you can hope that the next version will put an entry into your "Programs and Features" list. Now you never have to see this box pop up ever again:
Every time I would load Visual Studio this would pop up

Well that was easy...

Thursday, November 8, 2012

SSRS Report Viewer Control Broken Image Below Lines - Missing URL parameter: IterationId

I know it is unreasonable for me to say this but AXD files and anything that has to do with them scares me. I say this because if something goes wrong with them usually you can't do anything about it, it is part of the magic of Ajax and ASP.Net that you are not supposed to concern yourself with and you can't usually fix even if you wanted to. It is like a black box that always works, and when said black box stops working you are just left in a state of utter helplessness asking yourself "Well what do I do now?!"

Well this is the first time I have been able to find a work around for an AXD related issue.

The Setup
You run a report in a web application using the SSRS Report Viewer Control and unexpectedly to you you see a broken image icon under a horizontal line in your report (if you put one there, not sure if this happens any other time).

I originally thought this was because of my Sub Report, but it is the line I placed above it.

The Investigation
What was particularly irritating about this, is this only happens when I use Chrome! I am not sure why. So I right clicked on the broken image icon and selected Open image in a new tab.

I was presented with a nice Yellow Screen of Death as shown below.

The Experiment
I am a big believer in playing around with things that are broken already, it's not like you are going to make it worse especially when it is the black box that is blowing up. So it is complaining that it doesn't have an IterationId as a parameter in its QSP (Query String Parameters) right? Okay well add the #@$@ thing then. Why the hell isn't it there to begin with, damn you black box must I do everything around here?

If it is missing, then add it!
So I simply added "&IterationId=0" to the end of the URL's QSP

I pressed enter to refresh the page and blammo blank page which is what we want, we don't want that stupid broken image icon (why the hell is that there anyhow?).

Here is what the URL looks like:

Notice it is missing the IterationId parameter

The Stupid Fix to the Stupid Problem
Okay well we just proved that this can be fixed just by giving the beast what it wants, it wants its binky, so we gave it its binky. "But how do we do that programmatically without causing issues?" Well it is easy actually, I was searching for all of this nonsense on google and I couldn't find an answer to my problem in particular, I kept finding a similar issue about a "Blue Coat" which had a decent solution or a work around rather that I am using to fix this problem too (all credits and resources at the bottom).

In order to fix this problem we want to re-write the request every time, but only for chrome browsers and only in this particular case. Here are the steps:

  1. Go to your Global.asax code behind
  2. Add the following code snippet and add any other customization you might want to add.

void Application_BeginRequest(object sender, EventArgs e)
 //The following code is a hack for stopping a broken image from magically appearing on SSRS reports in chrome
 //where ever a line is used in the report.
 Uri u = HttpContext.Current.Request.Url;

 //If the request is from a Chrome browser 
 //AND a report is being generated 
 //AND there is no QSP entry named "IterationId"
 if (HttpContext.Current.Request.Browser.Browser.ToLower().Contains("chrome") &&
  u.AbsolutePath.ToLower().Contains("reserved.reportviewerwebcontrol.axd") &&
  HttpContext.Current.RewritePath(u.PathAndQuery + "&IterationId=0");

Run your code and viola, the broken image icon goes the hell away. Warning: I can't guarantee this won't introduce problems because I just solved this today, but hey, this is a good place to start.

Google Fu Results
https://www.google.com/search?q=Missing+URL+parameter%3A+IterationId - main search result
http://www.networksteve.com/enterprise/topic.php?TopicId=37516 - this exact article's complaint!
http://stackoverflow.com/questions/705359/reportviewer-missing-url-parameter-name - a similar complaint
http://forums.asp.net/t/1118527.aspx - a similar complaint
http://csharp-matt.blogspot.com/2010/06/effects-of-bluecoat-proxy-on-aspnet.html - blue coat stuff
http://social.msdn.microsoft.com/Forums/en-HK/sqlreportingservices/thread/b44a0452-d71a-4e69-b7e0-af74b9f6bde7 - this exact article's complaint with no answer
http://support.microsoft.com/kb/2120979 - the KB article with a supposed fix (I doubt it will work)
http://www.webdeveloper.com/forum/showthread.php?154780-Application_BeginRequest-in-Global.asax-not-working - URL Rewrite example

Wednesday, November 7, 2012

SSRS Logical Flaws of IIF

Déjà Vu
It isn't very often when I have to build reports for SSRS, it usually happens in bursts. I will write like 2-5 reports (sometimes more) and you always tend to find a bunch of shitty problems along the way, you tell yourself "Argh!!! I keep forgetting that it does that! I need to remember this!" Well I am having one of those moments again and this time I am writing it down. There is plenty of documentation on this, but I want to explicitly state the following:

IIF Is Logically Flawed
The IIF function is logically flawed in that it will evaluate both return conditions regardless of which path is chosen (true vs. false). Therefore if you are trying to prevent an exception from happening, usually arithmetic errors IE: Divide by Zero Errors or using a null value (Nothing in VB) for something that cannot take null, well IIF will screw you in this respect. This is best explained with an example:

Dividing by Zero Example
Let's say you are trying to compute the following simple equation: (x - y)/x, well right away we can see that if x is zero, then you have just earned yourself a divide by zero error. In SSRS that results in a #Error where you are expecting to see a value instead. Not very helpful, however, if it didn't pop-up already - your Error List at the bottom of your screen should pop-up and show you a warning.

More useful than #Error
This error reads:
Warning 1 [rsRuntimeErrorInExpression] The Value expression for the textrun ‘LatestCost2.Paragraphs[0].TextRuns[0]’ contains an error: Attempted to divide by zero.

Well the first thing you are thinking is "@#*&^$ the if statement failed! WTF!", well that is partially true pejorative remark. It did fail because it didn't meet your expectations, but it isn't an if statement, it is IIF statement which will evaluate both outcomes and choose the right path. I am sure there was a use for this at one point, but I would imagine by today's standards this is just a wasteful statement. It is great for constants! Just not so much on statements that have the potential to throw exceptions.

The Gotcha
Let's re-use the above equation (x - y)/x and let's say that expression looks like this:

'This will evaluate both outcomes and therefore will result in an exception
=IIF(Fields!x.Value) = 0, 0, (Fields!x.Value - Fields!y.Value)/Fields!x.Value)

As explained before this will result in an error if x is zero. The most straight forward (and more efficient) fix in my opinion is as follows:

The Fix
Write a function for your report. If you are unfamiliar with how to do so then follow these steps it is easy:
  1. Right click on a blank area of your report, NOT the report body (page) and select the Report Properties menu option. (Figure 1)
  2. Click on Code (Figure 2)
  3. Enter your Function using VB.Net syntax (I am not sure if everything is supported, play around).
  4. Press OK to save
  5. Go back to the expression that was giving you trouble and utilize your function like shown below:

Figure 1
Figure 2

Code Example
'Writing a function to take care of this annoyance
Public Function MyFunction(x As Decimal, y As Decimal) As Decimal
   If x = 0D Then
      Return 0D
      Return (x - y)/x
   End If
End Function

'Using the function in an expression
=Code.MyFunction(Fields!x.Value, Fields!y.Value)

Bonus Tip: If after changing your expression, your report generates without seeing #Error, but the stupid warning won't go away, even after a re-compile, close Visual Studio completely and open it again. That should fix it.

Like I said before, this has been solved and posted several times before. I just wanted to give a more in depth answer and explicit instructions on how to embed code in your report.