Wednesday, June 28, 2006

TransactionScope + MSDTC + Windows 2000

For my data access unit tests, I am a huge fan of the new System.Transactions namespace in .NET 2.0.  Basically I can define my unit tests like this:

using System;

using NUnit.Framework;

using System.Transactions;

 

[TestFixture]

public class TestClass1

{

    private TransactionScope _tx;

 

    [Setup]

    public void SetUp()

    {

        _tx = new TransactionScope();

    }

 

    [TearDown]

    public void TearDown()

    {

        _tx.Dispose();

    }

 

    [Test]

    public void TestSaveSomeData()

    {

        //some code that inserts data into the database

    }

}

Without the TransactionScope above, we would end up with a bunch of junk data in the database.

What’s great about this method, is that – from the bottom layer – I can start a transaction, do all kinds of inserts/updates/deletes and even select from that data, and then roll the entire thing back when I’m done.  (Even in the event of failure).

What’s not so nice is that TransactionScope uses MSDTC (Microsoft Distributed Transaction Coordinator) behind the scenes.  This is fine locally as long as you have the service running on your machine.  But what if you try to do this on a database on another server?

In my case I was connecting to a Windows 2000 Server on the local network.  The MSDTC handshake was failing.  This was due to security settings built into Windows XP SP2.

I received enourmous help from Florin Lazar’s blog post: http://blogs.msdn.com/florinlazar/archive/2004/06/18/159127.aspx

I opened up Administrative Tools -> Component Services , right-clicked on My Computer and selected Properties.  Under the MSDTC tab, I clicked Security.  Then I enabled Inbound and Outbound connections, and set the authentication to “No Authentication Required”.  That last part is kind of confusing, but basically it’s required for pre-XP/2003 machines, such as NT or Windows 2000.

Now my transactions are running again.

Visual 2005 ReportViewer Doesn't Work With MSSQL 2000

I was trying to connect a 2005 WinForms ReportViewer control to a SSRS 2000 report server and I kept getting an HTTP 404, even though the url was correct.

Apparently it’s not supported.

The error message did say “Make sure this report server is compatible with the ReportViewer” but I think that’s something that they should just come out and tell me.  I mean, come on… ReportViewer 2005 can easily recognize that I’m connecting to a 2000 report server.

I had to spend 20 minutes searching the internet to get a definitive answer.  Hopefully this will save someone some grief.

 

Tuesday, June 27, 2006

Is Songbird the media solution Im looking for?

I just discovered this today:

http://www.songbirdnest.com/

It’s called Songbird and I think they’re on to something.  Just admit it:  Our current media situation sucks.  I posted about this previously and ranted about how much I hate most media players.  Anyway, I settled for iTunes, but not because I love it, only because it’s the lesser of other evils (IMHO).

Songbird is taking a different approach to media players, integrating it more closely with the web, and it’s built on top of Firefox, so it’s cross-platform and have rich plugin support.  I’m really looking forward to some of the extensions that will become of this.

It’s based on XUL, which should impress some super-techies out there .   I wonder how nicely this will work with a distributed scenario like iTunes + FolderShare?

Tuesday, June 20, 2006

Adding connection strings at runtime

Today I noticed how non-intuitive it is to write to the configuration file programatically for an application.  What I needed to do was dynamically create a connection string, then write it to the app.config file.

Here’s how you do it:

first, you need to add a project reference to the System.Configuration assembly.  Add a corresponding using clause to the top of your class.

   using System.Configuration;

Next you need to find and open the configuration file.  In win forms, you do this by specifying the full path to your application’s executable.  If you project is at c:\code\project1 then you would pass in something like this: “c:\code\project1\bin\debug\project1.exe”.

 Configuration config = ConfigurationManager.OpenExeConfiguration(FULL_EXE_PATH);

 

 ConnectionStringSettings connStringSettings = new ConnectionStringSettings("database",

     "connection_string_here");

 

 config.ConnectionStrings.ConnectionStrings.Add(connStringSettings);

 

 config.Save();

For ASP.NET, you can follow the same principle, but use the System.Web.Configuration namespace in conjunction with WebConfigurationManager.OpenWebConfiguration(path) where path is the url of your root, for example http://localhost/webapp1 (notice there is no trailing slash).

Monday, June 12, 2006

Review of Domain Driven Design

Domain Driven Design – by Eric Evans

I just finished reading this book by Eric Evans on “Tackling Complexity in the Heart of Software.”  Domain Driven Design should really be required reading in college, in my opinion.  Eric Evans has a way of describing benefits of rich modeling techniques and how to develop them.  He guides you through learning to develop the ubiquitous language of the domain, an important concept for effective modeling.  He also addresses many common concerns such as scalability with the techniques in the book.

This isn’t your typical software book, chock full of simple examples to help make the author’s point.  Evans goes into enourmous detail on the examples and builds on them throughout the course of the book.  The quality of the examples are what pushes the reader’s understanding of the topic to a level that words cannot do alone.

Evans tends to be a bit wordy in this book, and you’ll often find that he seems to be repeating himself, frequently with the same verbage.  The message is important though, worth visiting more than once. 

Domain Driven Design is among the most profound, impacting, and inspiring software books I have ever read.  I give it a 5/5.

Dear Microsoft Branding Department: Retire!

Let me be the first (well more like the 50,000th) to say that re-branding WinFX to .NET Framework 3.0 is a STUPID idea.  (Yeah that’s right, I bolded it.)

Set aside for a second that it’s a bad representation of the product, there’s already a .NET Framework 3.0 in the works and WinFX isn’t it!  WinFX runs under CLR 2.0.  They should call it .NET Framework 2.5 or something.  WinFX will not include 3.0 features, such as LINQ.

Why, oh why, Microsoft?

WinFX was a cool name, and developers who were confused about the role of .NET in WinFX should just google it and read a tad.  It won’t kill you I promise.

/mourns the loss of Indigo, Avalon, and now WinFX in this Microsoft naming wtf’ery

Now playing: Keane - Untitled 1

Thursday, June 08, 2006

Debugging Javascript

I haven’t posted in a while, but I had to take 5 and post this today.

I stumbled across yet another fantastic plugin for Firefox today.  It’s called Firebug  and it rocks.

If you’ve used Venkman before, you will appreciate this.  Basically it’s a complete Javascript debugger + DOM inspector embedded in Firefox. Here’s a video of it in use.

Life in the web development world suddenly got just a bit sweeter.

48_firebug-debugger

On a side note, why are there so many good web developer tools for Firefox, and the ones for IE leave something to be desired?

Tuesday, May 16, 2006

About Me

My name is Ben Scheirman.  I am a Principle Consultant with Sogeti, a Microsoft Gold Certified Partner.

On this blog you’ll find my random tidbits about software development, revolving around agile practices such as test-driven development, refactoring, continuous integration, domain driven design, and more.  I also frequently cover object-relational mapping concepts with NHibernate.

I enjoy reading, but the only thing that captures my attention are technical books.  My reading list is growing faster than I can possibly read.

I live in Houston with my wife and three beautiful children.  When I’m not working, I’m usually hanging out with my family, playing video games, or playing guitar.

Monday, May 01, 2006

Venkat drops another winning analogy

Venkat Subramanium is an amazing speaker.  I was fortunate enough to have him as my professor in college and what I remember most are the interesting analogies that helped explain tough topics.

His latest post, Walking along the developer beach, is another gem that explains the rhythm that you must get in to gain the most productivity out of test-driven development (and test-2nd development).  The most interesting thing is that it works for either school.  Either you write the test first, then the method, or you write the method first, but immediately after you write your test.  It forces you to hold the caller’s perspective and not get buried in the code.  A byproduct is cleaner, more testable code.

If you are writing unit tests, then that’s a huge step that most people aren’t even achieving yet, but to get the most out of them, write them in parallel with your methods.  Otherwise you’ll be hopping along one foot, just like hopskotch.

Now playing: Breaking Benjamin - Wish I May

Loan - Mortgage Calculator - Homeowner Loans - Bad Credit Loans