sql comments edit

I’m going to combine days two and three into one big entry because I don’t think I’ll get a chance to do a full day-three review at the end of today.

Yesterday was day two and we looked at SQL Server 2005 service broker stuff, its native HTTP support, and Notification Services.

The service broker facilities they’ve added are pretty cool. The ability to set up messages and queues and such inside the server is neat, and it folds nicely into the native HTTP support to allow for exposure of these things via web service. Cool. SQLXML has rolled into SQL Server, which we all anticipated and love.

Notification Services, though… OK, I’m just going to be brutally honest:

SQL Server 2005 Notification Services sucks big fat donkey dong.


Notification Services is the biggest hunk of claptrap Rube Goldberg mechanics I’ve been introduced to in a long time. It’s not debuggable, it’s super-hard to set up, and for what it offers I’m not sure it’s worth the effort.

We had a lab to set up some rudimentary Notification Services. The lab involved us creating a lot of hand-cranked XML configuration, running some setup to get the services up and running, then testing it out.

Problem 1: The XML contains SQL that turns into stored procedures. Why is that bad? When they make the stored procedures, there’s nothing to tell you whether you have a typo in the SQL. I mistyped a database object name and it never had a problem with it. In fact, I found that error in the Event Viewer - not even in the SQL error log - and only when it actually tried to execute the procedure. NO!

Problem 2: There’s insufficient logging. After I corrected my error, I tried to use the service again and something else went wrong. What happened? I have no idea. It just swallows the errors and moves on like there’s no issue. No errors, no warnings, no log. How am I supposed to debug that?

The whole thing where the XML that you have to hand-generate (and there’s a LOT) has a lot of magic words in it that you just have to sort of “know” about (like you have to just “know” that when you type “Foo” in one element that it becomes a stored proc with a name like “ServiceFooSomeProcNameHere” - yeah, that’s intuitive. It really does work like Rube Goldberg machines - this bit of XML kicks this block of code out that rolls down the hill and knocks this table row down and flips over and tosses a message over to that service… Come on, guys. It’s like someone took a weekend, architected the thing, and clamped it on the side of SQL Server 2005 so they could have a selling point or something.

Today we’ll be learning about managed code in SQL Server 2005, which looks great; working with client apps (ADO.NET), which won’t be news for me; and SQL management objects, which also looks great.

Oh, and before I forget, tomorrow is Thanksgiving, so Happy Thanksgiving to all!

gists, csharp, net comments edit

I’m looking at different ways to provide caching from within an application so I can read in some information from a file, keep it in memory, and have cache dependencies perform a callback to update the cache whenever the file changes.

This is simple to do in an ASP.NET app using the System.Web.Caching.Cache object that you find in HttpRequest. Just add something to the cache with a cache dependency and you’re set. But what about if you’re working in a console or Windows Forms app?

I did an experiment and it looks like you can access the cache from any application as long as you access it through HttpRuntime directly. I haven’t tested to see if this works on a machine that doesn’t have IIS installed, but I don’t see why it wouldn’t.

Below is my experiment code. It’s a console app that reads/writes the cache with a file dependency that constantly changes. Running it, you can see that the cache is doing what you expect, just like in a web app.

using System;
using System.Diagnostics;
using System.IO;
using System.Web;
using System.Web.Caching;

namespace ConsoleApplication1{
  class Class1{
    const string KEY = "mykey";
    const string FILENAME = "dependency.txt";

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    static void Main(string[] args){

      for(int i = 0; i < 1000; i++){


    static void InsertItem(){
      DateTime t = DateTime.Now;
      Console.WriteLine("Inserting item into cache: {0:m.s.ffffff}", t);
          new CacheDependency(Path.GetFullPath(FILENAME)),
          new CacheItemRemovedCallback(CallBack));

    static void ReadItem(){
      object item = HttpRuntime.Cache[KEY];
      if(item == null){
        Console.WriteLine("Item is null.");
      else if(item is DateTime){
        Console.WriteLine("Item is {0:m.s.ffffff}", item);
        Console.WriteLine("Item is wrong type: {0}", item.GetType());

    static void WriteFile(){
      Console.WriteLine("Removing file.");
      FileStream stm = File.Create(FILENAME);
      Console.WriteLine("Wrote file.  File exists: {0}", File.Exists(FILENAME));

    static void CallBack(string key, object value, CacheItemRemovedReason reason){
      Console.WriteLine("Callback invoked: {0}", reason);

If anyone finds a problem with it, do leave me a comment with reproduction info. Seems to work, though, which is pretty cool.

sql comments edit

I’m taking Microsoft training course #2734B: Updating Your Database Development Skills to Microsoft SQL Server 2005. I’ve got my MCSD; I really just want to see what’s new in SQL Server 2005 and how to use it. Rock on, right?

Day 1, we covered a general overview of SQL Server 2005 changes (enough to give you a general idea of what the course will cover, but not enough to really tell you anything), some of the T-SQL enhancements they’ve added, and a bit on how they’ve updated the handling of XML in the database.

The first module, the overview, was pretty good for the beginners but really didn’t tell me much.

The second module, the T-SQL updates, was neat. They added some stuff that should have been there all along (ALTER INDEX, anyone?) and put some really cool things in for partitioning. When we got to pivot tables… well, I won’t lie. I generally understand the concept of pivot tables, but I’m not a data analyst and really don’t care to be, so when we got to the use of PIVOT and UNPIVOT, I took it in from an academic standpoint but I can’t say I totally get it. The new ranking operators are cool, though, and I can see how they would be very useful. And how can I forget the TRY/CATCH they’ve added? Love that.

The third module, on handling XML, got a little more tricky. I feel pretty comfortable in my XML skin and worked with SQL Server’s OPENXML and SELECT...FOR XML in the 2000 version, so that stuff wasn’t new. The added ability to format the output of the XML to the level now available is very welcome, as is the ability to store XML as a native data type (either validated or not).

So what have I seen that I don’t like?

When we got into the trickier parts of the XML stuff - updating values of attributes in stored XML fields, for example - the book got a bit sparse. The lab would instruct you to do something like “change the ‘foo’ attribute in the document stored in field ‘bar’ in the first row in the table to have the value ‘val’” and when you went to look up the syntax for that… well, good luck with that. I ended up opening the solution and seeing how they did it (at which point it finally made sense).

The biggest issue, though, is how arbitrary some of the syntax has become. It turns out that in some cases, T-SQL requires semicolons to end statements and in other cases it doesn’t. That makes it difficult, but I figured out that they don’t penalize you for ending every statement in a semicolon, so maybe that’s the new habit to get into. I also don’t like the inconsistency of the syntax - sometimes you specify options in parentheses, sometimes you don’t; sometimes the parameters for a method are in [square brackets] and sometimes ‘single quotes.’ The worst bit is that they seem to intermingle it all without any rhyme or reason, so you might call a function like FUNCTION_CALL MODIFIER([param1], 'param2') 'param3', [param4] even if all of the parameters refer to database objects. Consistency! Pick something and stick with it! It feels very much like all this was tacked onto the end of T-SQL and they did their best not to alienate previous T-SQL users but couldn’t quite make it happen.

Today, day 2, we’re looking at the native SQL Server 2005 service oriented architecture provisions. I’m liking it so far. Better than SQLXML, anyway. It occurs to me that you could potentially replace BizTalk with SQL Server 2005. I wonder if that’s what they were going for.

media, movies comments edit

Saw the latest installment of Harry Potter this weekend, and it rocks. I am so pleasantly surprised to see them get back to the books rather than taking too much “creative license” or whatever and ruining the thing the way they did with the last one. In all honesty, I wasn’t looking forward much to this one because I was afraid they’d butcher it like they did with the last one. Not so - this is definitely the best since the original movie.

I won’t review the plot, since there’s a whole book on it and you can find out about that online. The question is, “Should you go see it?” The answer is an unequivocal yes.

A lot happened in the book, and I don’t want you to think that they didn’t cut anything, because they did. The beginning, in particular, was chopped down. Nothing to be too disappointed about because from a plot perspective, you’re not missing much - a bit of character development and background, but nothing that would translate well to the screen. That said, the things that could be shown were, and they did a fantastic job with them.

The effects continue to impress me. With each episode, they get better and better with the effect quality and the level of sheer cool they throw out there. The magic, the creatures… it all totally looks exactly the way you imagined it, and it’s brilliance to see it happening.

What I’m most pleased with, though, is that the screen translation of the book retained the awkwardness of growing up that was so important to the ongoing character development. I was afraid that since it wasn’t a driving plot point they would nix it, but they carried it off well - the characters’ expressions and actions reflecting the whole time the changes that their lives are undertaking. It totally captures that stage of adolescence where you’re discovering dating and the social difficulties that ensue. Great in the book; just as great in the movie.

All the actors did a fantastic job, as usual, and the new faces… perfect casting. Love it. I don’t want to give too much away - you’ll just have to see.

Long story short - check it out. You’ll be glad you did.

I already can’t wait for the next one.

coderush, vs comments edit

Previously the CR_Documentor plugin made its way into the Visual Studio Hacks site in an article called “Ask The Pros: Visual Studio .NET Addins.” Today it makes it in with its own dedicated article. That totally rocks!

I noted in the article that one of the downsides of CR_Documentor mentioned is the lack of support for included files. Not to worry; I’ve been noodling on how to make this work in a performant fashion. Not forgotten, just not quite here yet. There are other things I want to add, too, like the little gray box that shows the method signature in the doc and so forth. We’ll see what we can do.

Something the article doesn’t mention is the context menu that gets added to the code editor with CR_Documentor. It adds a lot of helpful commands that allow you to expand/collapse the XML comment blocks in your document, convert text blocks into XML comments, XML encode selected text, and insert XML comment block templates (among other things).

If you haven’t already, check out CR_Documentor.