Monthly Archives: February 2008

LINQ to SQL Visualizer isn’t in the transaction it is visualizing

The LINQ to SQL Visualizer is a phenomenal tool.  This is how debugging should be done.  Scott Guthrie introduced it in the Visual Studio 2008 Beta 2 timeframe, and I’ve been hooked ever since.  It’s now bundled in the Visual Studio 2008 RTM samples, though it’s not installed by default.  Instructions of how to install it are here.

Well, I’m splunking along in some code that happens to be in a transaction.  I’ve just inserted a row, and I’m about to execute the select that refreshes the business object with generated content including the primary key.  I open up the Visualizer, and push the Execute button.  Nothing happens, and the window freezes.

It dawns on me that the unit test’s transaction has locked the row in question, and the Visualizer can’t get to it.  Well, that’s all fine and good, but why wouldn’t it be in the same transaction and/or join the transaction and/or create a rollback point in the transaction in process so the “execute” button can be undone once the window is closed?

I emailed Scott Gu, and he passed on my question.  (Scott is phenomenally awesome with email, by the way.  I can only imagine how many emails he gets from users across the globe, and each time I email, I get a personal response.  I hope I can be that awesome when I grow up and get an office with a window.)  The answer came from a tech that Visualizers don’t use the same app domain as Visual Studio, so reusing the connection was impossible, making subscribing to the transaction also impossible.

Since this is sample code, and thus the code is provided, I’d like to take a stab on an off hour changing the sample to store the SqlConnection (or IDbConnection) rather than the ConnectionString and see if it works.  I expect it won’t, but if it did, wouldn’t it be cool?

In the mean time, I’ll just remember to look in the LINQ to SQL Visualizer but not execute if I’m inside a transaction.  If I’m that curious, I’ll grab the query, finish the transaction, and execute it inside Sql Management Studio or LinqPad.

Rob

Compile time reminders

For ages I’ve wanted to be able to put a comment of some kind in my code that I could get to come up during a build.  “Hey, you haven’t finished this” or “This is an assumption we need to run by the suits” or “you dork, how could you even think to do it this way” or similar — notes to myself and others that there is work left to be done here.

Well, after trying unsuccessfully to look towards subclassing or hacking the Obsolete attribute the answer was handed to me:

1. I build comments in the form // TODO: or // ASSUME: or // BROKEN: or similar, I choose the View menu, and choose Task List.  Ok, granted, that’s been there since the beginning of time, but who put that there and why didn’t they tell me?  Holy cow, that’s cool.  I can even configure it with my own set of commentaries like // DORK_MOVE: or // INSECURE: or // WHAT_WERE_YOU_THINKING:

2. There’s a pre-processor directive called # warning.  Put what ever message you want after, and it shows up in the normal error list.

With these two tools now in the arsenal, I can capture my thoughts in the place most relevant to the task at hand — in the code.  And I can be reminded of them in the place most relevant to the task at hand — the next tab over from the build output window.  Very nice.

Rob

Filter Sql Server Profiler by Database

Ok, I stumbled with this one enough times to log it here.  I want to tune a database I’m working with.  I dutifully fire up Sql Server’s Profiler, and no where in the options do I see “filter by database”.

Ok, the option is there, but it takes some doing to get there.  When you’re building the profile, in the events selection tab, choose “show all columns”, then you’ll find the “Database Name” column.  Pop in the database name in question, and you’re golden.

source: http://sqljunkies.com/Forums/ShowPost.aspx?PostID=14078

Thinking in JavaScript for the C# Developer

I had the great privilege and honor of presenting “Thinking in JavaScript” at the SouthEast Valley .NET Users Group this evening.  All in all, I had a ton of fun.  If anyone else got anything out of it, all the better.

The main point of my discourse was that JavaScript isn’t hard by any means, it just takes an introduction to how it thinks.  Microsoft’s ASP.NET AJAX has made it feel much more like the .net languages we’re used to.  But there are still some inherent differences between a compiled language and a dynamic language.

The main focus of the discussion is these few points:

  • Every object is a Dictionary.  In C#, think of Dictionary<string,object>.
  • Functions assigned into the object’s ‘dictionary’ are like methods.
  • Functions are objects, and can be assigned like variables.  In C#, think of delegates.
  • Every parameter in a function is optional, allowing for uber-easy “function overloading”.

We also covered incredibly cool tools for working with JavaScript:

You can open up MicrosoftAjax.debug.js file by cruising to C: Program Files Microsoft ASP.NET ASP.NET 2.0 AJAX Extensions v1.0.61025 MicrosoftAjaxLibrary System.Web.Extensions 1.0.61025.0 *.debug.js (spaces added for clarity)

And the coolest thing of all — anything built in JavaScript is available for download by choosing “View Source”.  When you publish anything in JavaScript, you don’t publish a compiled assembly, you publish your source.  Thus anything created in JavaScript becomes awesome reference material — bonus!

The slides for this are in Powerpoint 2007 format and available here.  The code we walked through was from Rob Bagby’s webcast series on the ASP.NET AJAX Client Libraries available from his blog: blogs.msdn.com/bags/archive/2007/06/07/latest-asp-net-client-libraries-webcast-sample-code-and-links-to-all-sessions.aspx and blogs.msdn.com/bags/archive/2007/06/07/links-to-remaining-asp-net-ajax-client-libraries-webcasts.aspx

Thanks to all who came — you got some cool swag, and thanks to our sponsor who bought the pizza and showed us just how much we love LINQ. :D

Rob

DropDownList’s SelectedValue in JavaScript

Ok, I’ve forgotten this more times than I care to remember, and each time, I have to re-Google it.  I hereby commit it to digital memory:

If you have a DropDownList control like so:
     <asp:DropDownList ID=”mycontrol” runat=”server”></asp:DropDownList>

and you want to get it’s selected value in JavaScript, do it like so:
     var control = $get(‘<%= this.mycontrol.ClientID %>’);
     var selectedvalue = control.options[control.selectedIndex].value;

And there ya have it.  I hereby have forgotten it already… :D

Rob

Double-click the document in Solution Explorer -> Code View by default

Ok, this has been an annoyance for long enough.  I’m in Visual Studio.  I double-click on a web service’s code behind file in the Solution Explorer, and up pops an empty designer window.  I close the irrelevant window (once it finishes loading), right-click on the file, and choose “View Code”, then promptly kick myself for doing it again.

The solution comes from http://www.thescripts.com/forum/thread106933.html:

If you want to go to code mode by default, do the following:

1) Right click on the document name in the Solution Explorer
2) Choose “Open With”
3) Select “Csharp editor”
4) Choose “set as default”

I did this, and I’m golden — no more designer for web services.  Ok, I could still get to it if I right-clicked on the file name in the Solution Explorer, and chose “View Designer”, but when would I ever do that?  I can also put it back with this method just by choosing “Csharp form editor”.

Advantages: does it for all documents on my machine.
Disadvantages: doesn’t do it for anyone else, and I can’t do it per document, only per file extension (I think).

I recall in the crustaceans of my brain a way to do this via an attribute or pre-processor directive in the code file, but I can’t find it.

Rob