Jan 26

SSMS Crashed!!!! Now What?!?!?!

You’ve been working on a big ugly query for the last two hours and it’s all but perfect.  You make one final tweak and then press Execute…

SSMS Stopped Working

After you finish throwing your copy of “Introducing Microsoft SQL Server xxxx” across the room and cursing yourself for not saving your progress you start to think, maybe there’s an auto-save file like Word or Excel, it is a Microsoft product after all.

What Can Be Done Now

After a brief web search you discover that there should have been backup files in your:

  • \Users\<username>\AppData\Local\Temp
  • \Users\<username>\Documents\SQL Server Management Studio\Backup Files\<solution>
  • \Users\<username>\My Documents\SQL Server Management Studio\Backup Files\<solution>

But you were not working with a solution and/or auto save didn’t do a thing for you…

If you had executed the code prior to the crash this query may be able to fine the script if the server still has it cached:

USE [(database)]
-- Parameters
DECLARE @Search nvarchar(MAX) = '(search word or phrase)'
DECLARE @Hours int = 1 -- query is not fast, this helps.

DECLARE @StartingWith datetime = DATEADD( hh, -@Hours, GETDATE() )
SET @Search = N'%' + @Search + N'%'

	[Executed On] = a.last_execution_time
	,[SQL Script] = b.text
	sys.dm_exec_query_stats a
	CROSS APPLY sys.dm_exec_sql_text( a.sql_handle ) b
	a.last_execution_time &gt;= @StartingWith
	b.text LIKE @Search
	a.last_execution_time DESC


In The Future

To prevent problems like this in the future you may consider running a tool like SSMSBOOST which is a great tools for protecting you from yourself.  It specifically has a feature called “Recent Sessions” that (according to the documentation) will perform “autorecovery of recent sessions, including unsaved documents and their connections”.

Jan 09

The Bureaucracy of Software Design

So I am visiting Washington, D.C. and I cannot help but notice how convoluted and inefficient the travel is here.  There are roads that go literally nowhere and no way to manage the vast numbers of pedestrians and cars that are moving in and out of the city at any given time.  Additionally, if an unexpected (but predictable) event occurs(e.g. snow) then the entire transportation system is crippled.

First I performed the typical tourist tirade about how L’Enfant could have done better with the design of the city and commented on the irony of politically stalled government operating from a functionally stalled city.  Then the architect in me started looking at the reasons for the for the problems.

When Washington advised L’Enfant about the design of the city there was method to it.  With only ground forces and ships an enemy had to take a city with soldiers on the surface roads.  The city was built to confuse and slow an invading force and allow city defenders to repel the attack.  Washington probably took this lesson from his own victory at Trenton a few years earlier where he used two cannon emplacements on a hill at the head of King and Queen street to effectively control the entire city.  Much like software this wonderfully thought out design failed too when the British invaded in 1812 and burned the city.

If the city were an agile software project this would be the point where management (the chickens) sense that things are not right and the project manager, leads and developers (the pigs) start feeling their bacon getting cooked.  Often times whole teams are replaced and the new team is given unrealistic goals of re-designing the entire system so that this will not happen in the future.  The expectation is that the new team, by virtual of being new, will have answers that the old team did not.  The new team will start looking at the existing code to see what can be salvaged and more often that not discover that most of it contains good ideas and should be kept.  Then by placing necessary fixes everyone is satisfied because they are no longer under attack.  The new team is very good and they build an elaborate set of tests that simulate the problem and “prove” that it cannot happen again.

The city grows and new functions are incorporated to support the ever increasing scope and user base.  Certain flows become “mission critical” and cannot be interrupted.  Certain structures (e.g. monuments) become so sacred that merely mentioning an alteration is an unforgivable sin.  Rarely are existing structures completely removed and re-built opting instead for the most cost effective retrofit and re-purpose.  After a while the “technical debt” becomes unmanageable and architects begin clambering for a re-write, but there is “too much invested” or the “cost is too high”.

In Washington, D.C. we can see this in the roadways that could not be changed because of historic significance, or because they were too “mission critical” to close and rebuild.  The city architects are still laboring under the original set of designs that called for a city that would confuse an invading force but is only serving to confuse the commuters and tourists.  The resulting inefficiencies are causing the system to become overburdened and failure has become the norm.  Now a successful project is one that does not “break” the system while adding new functionality.

In the software world we have some tools to solve these problems.  I am sure the city planners would like to create a new bridge and just “deploy” it when the project is complete.  But like Uncle Ben says, “with great power comes great responsibility.”  All too often developers are lulled into thinking that the new code has all of the functionality of the old code and will perform as well under pressure.  Even with testing against all know requirements it gets the “I worked at my desk” stamp and is deployed.  Once deployed, undocumented functionality provided by the old code is not longer provided and related systems fail.  Depending on the severity this could lead to a whole new round of “bacon in the fire” and all progress brought to a screeching halt while the “root cause” is addressed.

By this time you are probably wondering where I am going with this post and whether you’ve wasted your time reading the whole thing.  I was recently reading some articles about “microservices” and realized that this is really where we all need to be in our thinking.  As Martin Fowler says there is no one definition but the general idea is that we write “modular” and “maintainable” code.  I know, right off the bat you’re saying that will entail writing the same routines over and over again.  And if I write them in a library that I share across many microservices then I am in no better shape that I was before.  I am not proposing a universal solution for all problems, but if you write testable and tested code and you rely on a package delivery system to host your common packages, then microservices become a cost effective and maintainable proposition.

I will continue this line of thought in my post “One of Many Ways to Implement Microservices” post.

Back to the fair city of Washington, D.C. where technical debt has led to an escalating cycle of problem response over problem resolution.  It will become necessary at some time to solve the problems and the solution needs to be done in a way that is maintainable.  Like the Constitution of the United States, it should also be flexible so that change does not cripple it at every turn.  Likewise, if you are in a project where you are drowning in technical debt, consider a parallel project path to start relieving the pressure and eventually replace your system with a more manageable one.

The city planners in D.C are not totally beaten.  They continue to introduce rail systems and other alternate methods of transportation to alleviate the problems, but they have not kept up with the growth.  Until a major, and costly, initiative is undertaken to re-think the way the city operates it will continue to suffer pains.  I do not envy city architects and planners as their mistakes and design problems affect them for years to come.  As software developers we are blessed with a higher cycle rate for change and control, but if we code with the mindset of deploy now/fix later, then we WILL add unnecessary technical debt and ultimately cost.  We have to walk the fine line between “perfect code” and “passable code” and try to minimize the defects or relegate them to areas with the least impact.

Most successful developers will tell you that their success was achieved by learning to balance the cost, requirements and perfection of the code.  If you take too long to write a system, the company may starve to death.  If you release bad code the company might choke on it.  Work with your project owners and understand the nuances of the project and business needs and keep that conversation going throughout the project.  Do not let code become sacred.  And above all, constantly look to the future to support your evolving business, “we’ve always done it this way” is never a good justification.  Finally, when possible try to make your software life-cycle as short as possible so that you can be more responsive to change.

Bottom Line: Leave the bureaucracy out of coding.


Jun 12

C# Process.GetProcesses()

This post is me venting and scratching my head about a problem that I’m having with XP and Process.GetProcesses().  There’s no code in this article but I would be glad to share if you need help with the problem space.

So I have this code that has been running for quite a while without incident and then it just stopped working.  The environment is a group of Windows XP machines (yes we have to use them because they are hosting Paradox for Windows and it just doesn’t work right on Vista+).  The program is a call launcher that opens a Paradox form inside the running application and starts the query process for the incoming phone number.

Program Flow:

  1. Find the window with “pdox9” in the name.
  2. Focus on the window
  3. Inject the keystrokes to open the form and start the query

Well, to find the window i needed to enumerate the top level window and look for the window title that contained “pdox9”.  I used the Process.GetProcesses() command from System.Diagnostics and it worked like a champ.  The program has been in production for almost two years now without any issues and suddenly I started getting reports that it was not launching the Paradox query window any longer.  I tested it on a Windows 7 box and it worked fine.  I tested it on the problem machine and it failed.  I tested it on another XP box and it worked fine.

Long story short, even the isolated XP virtual environment that I originally used for testing now failed when I started it and ran the program.  I had to change my logic to use the User32 EnumWindows to get the code to work.

I cannot be certain but this problem appeared to start about the time XP end of life was announced.  The problem was isolated to a few machines at first but is now affecting many more.

Let me know if you’ve had similar situations, I would certainly like to know what happened.  So far I cannot find a common update, patch or system change that correlates to the failure.


Oct 29

IIS 7.x+ And Intercepted Responses

I’ll be brief because you’re probably hung up on this issue and need a fast answer.

IIS is overriding your custom error messages in your ASP/MVC/NancyFx/etc… website by displaying the most horrible 500, 404, 401, etc… error pages.  Your application is getting the request, generating a response but it’s being intercepted before it’s returned to the client.

Quick Answer:


protected void Application_EndRequest(object sender, EventArgs e)
<span style="font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; font-style: normal; line-height: 1.5;">  System.Web.HttpContext.Current.Response</span><span style="font-family: 'Courier 10 Pitch', Courier, monospace; font-size: 13px; font-style: normal; line-height: 1.5;">.TrySkipIisCustomErrors = true;
</span><em id="__mceDel">}</em>


  &lt;httpErrors existingResponse="PassThrough"/&gt;

Make sure that you’re handlers are in place and this should solve the problem.


Aug 16

What DHCP has to do with UDP Broadcast/Multicast messages

Once upon a time everything was working fine, then the product was deployed to the live environment (or a test server) and everything came crashing down around you…

This is pretty much the situation that I ran into recently with UdpClient and broadcast messages.  The code has been working fabulously for months, works in the QA environment, works on the developer machines, works on my laptop.  Then when the code is deployed to the DMZ for final testing-on the acceptance test site-the code ceased to work.  At the root of the problem was an otherwise sound SLP (Service Location Protocol) client.

My application employs an SLP (Service Location Protocol) “like” service that allows me to deploy and manage my sites and services with a common configuration source.  The premise is that the sites will broadcast a request for a particular service using UDP and the DA (Directory Agent) will respond with the appropriate information required to spin up the site.  The code is very short and straight forward and has been working for months.

The code creates a UDP client and then sends the broadcast message.  The message is received by the SLP server and responds with the requested information.  Part of the message stack performs encryption and decryption of the messages, etc.


When running on a machine in the DMZ no responses to messages sent out on the network.


After considerable testing I determined that using the default constructor for the UdpClient sets the local endpoint to the IP address associated with the DHCP server on the local network (the first encountered if there are multiples).  If no DHCP server exists (i.e. in a DMZ where everything has static IP addresses) then it defaults to a endpoint.  The net result was that there was no way for the SLP server to respond to a message (if it even saw it) from a host on


To remedy the problem I modified the code to use the default network adapter on the machine if no DHCP server could be located.  The process is simple enough and it now works in all of my environments.

I hope I have saved someone else the headaches associated with the UdpClient default behavior.

* I will add the UdpClient initialization code later and DHCP server locator code later – check back.

Apr 15

TinyIOC, NancyFx and Resource files

So if you’re using NancyFx or TinyIOC and auto-registration you’ll probably run into this little gotcha.  When you have multiple resource files with the same name (even if they are in different assemblies) then you will get the error “An item with the same key has already been added.”


To correct the problem you can do one of two things:

  1. Rename your resource files so that they don’t conflict.
  2. Add the offending assemblies to the ignored assembly list before auto-registration is called and register the relevant bits directly.

Hope this saves someone time when they hit this error.

Feb 28

Dell Printers and SLP Woes

While this is not something that we would want to do intentionally, if you run into this problem you might want to see if your situation is similar to ours.

In our organization we use Dell printers to print thousands of pages of faxes and other documents every day.  We have a large number of Dell 5530n, 2145dn and 2335 printers handling a majority of the work load.  One afternoon they all stopped working at the same time.  Because they are all served by the same print server we thought that maybe it was a print queue issue.  Testing with direct IP printing worked sporadically, but still failed.  We tried restarting the print server, printers and switches to no avail.  Since we had not been able to determine the problem from the printer’s perspective we started investigating what had changed in our enviroment.

We determined that recently a custom SLP (Service Location Provider) client and server had been deployed to new workstations just prior the failure.  The network enabled application talked on port 427 (UDP) so started investigating the network traffic.  The application only made six (6) SLP requests when it started and then remained quiet until it was restarted.  Although skeptical (because we thought it was a DoS type problem), we disabled the SLP services on the Dell printers.  To our surprise they began to work immediately.

Our conclusion is that the SLP service implementation on the Dell printers does not handle a ‘malformed’ or unrecognized packets very well and ends up locking up the print engine.  Since we have a managed network with defined print queues and no services that require printer announcements, disabling SLP is not an issue for us.  Additionally, the problem seemed to be limited to the Dell’s hardware and did not affect any of our HP printers equipped with SLP.

When I’m not so busy I will recreate the problem and identify the offending packet signature.  Until then, be aware there is a problem and we have made Dell aware of it.


Feb 26

My New Desk

I am so excited, my new standing desk has arrived.  If I can find time during the day to set it up I will and let you know how it works.  I’ve been so busy so far all I’ve been able to do is get the boxes to my office and look at them.

I have been standing at my desk since last October and I have to say that I am now wondering why I didn’t do this before now.  I feel better during and after the day and my productivity is much higher.  It’s also pretty hard to fall asleep standing up after a big lunch on a warm afternoon.

Here’s what my new desk looks like….GeekDesk


Feb 03

Vertical Bar-codes in Telerik Reporting

So I’m working on a report and I need to add a bar-code on the left or right side of the page.  The bar-code needs to include the page number and uses the total number of pages in the expression to determine the format of the contents.

I tried putting the bar-code in a header or footer and making the position exceed the bounds of the parent container.  This didn’t work as Telerik Reporting clips the elements that extend beyond the container borders.

I tried referencing the report data using the Exec command in the expression, but could not reference the global variables.

I contacted support and the response will work but it seems like a hack.  The idea is that I would use a text watermark and a bar-code font of the appropriate type and render it in on the report.  The watermark expression has access to the PageNumber and PageCount global variables so my expression will work fine.  Because my application uses Code 128 I  will also have to write a subroutine to calculate the check character to append to the bar-code text.  Additionally, I would have to deploy the selected bar-code font with my report for proper rendering.

In cases where I would render this report to HTML or present the report to users in an interactive setting I would also have to insure that the fonts were delivered to the client.

Finally, there are a number of free bar-code fonts, you should find one that meets your license requirements.


Oct 09

Telerik Reporting – ObjectDataSource Preview Error

I have been evaluating the Telerik Reporting tools Q2 2012 release for use in our organization. One of the issues that I saw during my evaluation was an error message when I attempted to preview a report.  The error said something to the effect of “error occurred while invoking data retrieval…object reference not set the the instance of an object…”.  The weird part of this is that the report ran great in integration testing as well as at run-time, only the designer was suffering from this problem.

Error received when trying to preview report with ObjectDataSource

What I’ve been able to determine so far:

  1. The problem seems to be related to the Telerik.Reporting.ObjectDataSource object.
  2. The problem only occurs in the designer.
  3. The problem usually happens when you have had an error in the ObjectDataSource object or a backing object.
  4. The problem is apparently cached and the only way to clear that cache (that I have found) is to restart Visual Studio.
  5. When this problems happens with one report, it affects all reports using ObjectDataSources after that point and up until the IDE is restarted.

I have created a testing class from which I call the report and I can use that for testing in development when the problem shows up.  It saves me the trouble and time of re-starting Visual Studio.  I have read that there might be a fix for this in the Q3 release.  I will update this post when I get the release and test it.

Additionally I have an open support ticket on this issue.

This post potentially describes the issue, it would explain the symptoms:


— Dave


I have found that when I use a parameter that allows NULL values I can create this error, but when I remove that setting it seems to clear up issues (after restarting the IDE of course).