Archive for July, 2005

Slow MySql ODBC Connection on Windows 2003

A little while back, I was trying to run a method asynchronously when my page loaded.
I wanted the page to load while the method was running, because the
results of the method did not affect the page load.  I ended up
figuring out why the method wasn’t running properly (I was losing my
HttpContext), but not only that, I figured out why the method was
running slow in the first place. Since fixing that problem, the method
can run synchronously and not affect the page load time, heres the
situation:

The page was calling a method that interacted with a remote mysql
database.  The web server is a 2k3 standard edition while the
database server is windows 2000.  I was using the MySql ODBC
driver to connect to the database, and the database and the web server
are on the same internal lan, so I was addressing the server like this
“server=192.168.168.11”.  What I noticed happening was that it was
taking approx. 50 seconds simply to call OdbcConnection.Open(). 
Now in this method I was doing a lot of database stuff, so thats why
the method was taking so long, and why I wanted to let it run
asynchronously.

After realizing that that wouldn’t work, I set out to find out why
the database was taking so long, when the servers were right next to
each other.  So I did some searching and didn’t really find
anything useful.  I was trying all kinds of connection string
settings, options, different server names, and I tried connecting to
the database from another 2k3 (web edition) machine, which worked
fine!  I did some more searching and finally found this solution,
which at first I didn’t think would apply since it has to do with dns
and I was addressing the server by its internal ip anyways, but I gave
it a shot.  Basically what it says to do, is set up reverse dns
for the database server because apparently, even if you address the
server by ip, the odbc driver still does some dns work.  So we set
up reverse dns, tried connecting, and the connection took .25 seconds,
whew!  So now that the initial problem was fixed, we were good to
go.

I’m hoping that other people who are having the same problem as I
was find this post if they do a search cause I wasted about 4 hours
tracking this down :-)

Mark Cuban, what are your thoughts?

This is a completely non tech post, so I’m going to try to keep it off the codebetter.com front page.

I just wanted to comment on the recent news about the NFL holdouts,
Terrell Owens in particular.  Owens signed a 7 year $49 million
contract before the 2004 season started.  He had a fantastic 2004
season, and now hes holding out because he wants a NEW contract in
light of his spectacular stats.  Now, most players like the
stability of a long term deal, its nice to know that you’ve got a solid
contract for a few years.  Why the hell should Owens get to demand
a new contract?  If he wanted to hedge his bets and sign a one
year deal for 2004, have a great year, and then sign another deal, he
certainly could have done that and I’m sure the Eagles would have
complied.  If this becomes the precedent, why would a team ever
sign someone to anything other than a one year deal?  If the
player is simply going to play and then as soon as the time is right,
completely disregard the current contract, whats the point?  TO
wants to have the comfort of a long term deal, but he also wants a
sliding pay scale, which, I might add, he could have worked into his
current 7 year contract by putting in performance based incentives, but
apparently TO doesn’t believe in himself enough to make any extra money
contingent upon his performance. 

If his market value has gone up significantly since he signed his deal,
then kudos to the Eagles, they got a great deal.  Meanwhile TO has
to “get by” on a $7 million average salary, I mean surely he’s got a family to feed somewhere, right? Right?

I would love to hear Mark Cuban’s
comments on this situation, as hes got a great mixture of sports and
business knowledge, thats why his name is in the title of the post, if
hes like most bloggers, he probably watches for his name to appear in
posts, so hopefully he sees this in IceRocket :-) .

Long running method

I had a page that took a long time to load and since the result
of the processing had nothing to do with the rendering of the page, I
wanted to run the long method asynchronously, since I didn’t need to
wait for it to finish anyways. So I tried the code below, but the
method just never runs.  I even tried putting a try catch block
around the entire thing and if an exception was thrown I was writing it
to the application event log, but nothing showed up there.  I’m
thinking that this has something to do with the Request life cycle but
I’m not sure, does anyone out there know why my method wouldn’t run?

    /// <summary>
    /// Summary description for WebForm2.
    /// </summary>
    public class WebForm2 : System.Web.UI.Page
    {
        private void Page_Load(object sender, System.EventArgs e)
        {
            WaitCallback callback = new WaitCallback( MyLongMethod );
            ThreadPool.QueueUserWorkItem( callback, Request );
        }
 
        private void MyLongMethod(object state)
        {
            HttpRequest request = state as HttpRequest;
 
            //
            // do a bunch of stuff that takes a long time......
            //
        }
 
    }

feedlounge review

I just today got my feedlounge account.  feedlounge is an ajax-based rss aggregator.  Think bloglines with no postbacks and an interface similar to outlook.  This is my initial reaction after playing around with it for a little bit.

Having developed a couple of large scale ajax applications myself, I feel like I can evaluate them fairly well.  I like that you can switch views from horizontal (outlook express) to vertical (outlook 2003) styles.  This is key, because I know some people are very particular about how their lists are arranged.  I personally like my email in the vertical (outlook 2k3) style, so I set up my feedlounge in the same style, but then I realized that I couldn’t resize the columns, they are fixed width.  This is tough because for reading blogs, real estate is at a premium, I want to be able to give as much space as possible to the posts, if I could hide the list of items entirely that would be optimal and shouldn’t be too difficult to implement. When you are viewing an item there are arrows to navigate forward and backward through the items in a feed, I’d like to hide the list and just use the arrows for navigation.

The responsiveness is hard to gauge because its only in alpha stage and they haven’t fully ramped it up yet hardware wise.  However, given the small scale that they are on, its keeping up pretty well, I think they have over 200 users on one server and its acceptable.  As soon as they get the servers they’ve ordered I think it will be much better.

One feature that is missing is search.  I don’t see anyway to search through my feeds for a particular item.  You can “Flag” items for lookup later on, which is nice. When you flag an item, you can access it by clicking the “Flagged Items” link on the left.  I can’t help but compare this to bloglines, when you “flag” an item in bloglines, it simply keeps that item as unread in that feed, rather than move it to a flagged area, which I like better because I can look at my feeds and tell where I have unread items and it keeps my saved items in the context of the feed they are from.

A feature that bloglines doesn’t have is the ability to ‘tag’ items.  This is awesome.  You have a user defined list of tags that you can apply to any item, so when I’m looking at pics of Jessica Alba from forgetfoo, I can tag the item in my ‘babes’ tag for later reference.  This sort of organization is great because it affords the user more control, regardless of how the blog author intended the post.

One last thing, both the list of items in a feed, and the item detail panes are set in a ‘div’, so the mousewheel doesn’t work in firefox.  The fix to this is to put them inside of iframes rather than divs, you can still set the innerhtml using dhtml, but it makes the mousewheel active in firefox, so that would be nice to have.

In general, I think feedlounge is a really cool example of what ajax can do, but I doubt that I would switch from bloglines to feedlounge as my main aggregator, especially if its not free.  The simplicity of bloglines is the deciding factor.  I get my new items, if I want to save one for later reference, I can mark it as unread.  You can search through your feeds for a particular item.  I like that as soon as I read an item in a feed, its gone unless I search for it again.  With how many blog posts you read in a day, I don’t want them accumulating like emails in an inbox, I want them gone for good, so long as they’re searchable later.  This is why I think that an email style application isn’t neccesarily the best model for a blog aggregator.  I want the items in my aggregator to be about the here and now, and if I deem it worthy to be stored, I can make that choice.

I’ll keep using feedlounge to see if my opinions change, but its looking like bloglines for the long haul.

 

Summer of Change

This summer is turning out to be the most life-changing time of my life.  I got engaged last August to my lovely fiancee, Erin, and our wedding is rapidly approaching, on September 24th. Getting married has always been “about a year away” but now its “about two months away”, so I’ve got to start getting my shit together :-)

Erin and I are also right in the middle of buying a house.  Our offer has been accepted, and now we’re getting our finances together while the seller takes care of some issues we had with the house.  I gotta say, the process of buying a house is so tedious and time consuming, its incredible. We’ve been looking for a house for over two months, and its taxing.  I’d leave work at 6:00 to meet our realtor, we’d look at three houses around Minneapolis and St. Paul, and then I’d get home around 8–8:30 and get to unwind. So now that we’ve found a house, I’m really excited, while the process has been long, its definitely worth the wait.

And the last big change this summer is my job.  I’ll be leaving Digital Array in three weeks to start my new job at Magenic.  Marrying Erin has me the most excited, but between the house and the new job, its a toss up.  I’m absolutely thrilled to have the opportunity to work at a place thats so well known and well respected as Magenic, and to boot, the office in Minneapolis is where Rocky Lhotka works out of (when hes not off doing speaking).  I think of all the blogs that I read, if I had to pick a few people to have the opportunity to interact with, he would certainly be towards the top of the list.  I’m hoping to blog about my experiences there, it should be a blast.

Handy context menu item

Heres another little thing that I’ve done recently to make my life a little bit easier.  I added a custom context menu item for my NAnt build files so that I can right click them, and build them from explorer.  Here a screenshot:

Here’s how you can do this (this works for any file type and custom action you want):

1. Go to the “Tools” menu and select the “Folder Options” item in any explorer window.

2. Select the “File Types” tab.

3. You should see a box with all your registered file types on your system, locate the .build extension.  If it doesn’t exist, create it using the “New” button that you see.

4. After selecting the .build extension, click the “Advanced” button towards the bottom.

5. You should see a list of actions for this file type, click the “New” button.

6. In the “Action” field, put “Build This!” or anything else you want. For the “Application used to perform action” browse to your nant.exe file, wherever you installed it to.  If there are spaces in the path, make sure to enclose the entire string in quotes.

7. Outside the quotes, add this to the end of your path, “-buildfile:%1” (without the quotes).  This tells nant.exe to build the file that you’ve right clicked.

8. Click OK on all the windows, close them, and you’re all set to build from the context menu!

Now, someone could get really rad and create a whole sub-context menu with a bunch of different nant command line options.  All we did was add the -buildfile option, but maybe you want to have a Debug settings, Release settings, etc, etc.  It could get pretty cool.  So someone do that and then let me have it :-) .

Community Server RSS Feed

I’m doing a little side project for myself that deals with rss, so to
test it I’m using the codebetter.com bloggers feeds. A little quirk (I
think) that I found is that the rss feeds that are produced from
Community Server have some weird elements. For instance, the
<author> element does not exist, instead it uses a
<dc:creator> element which contains the author of the post. 
Another one is the <comments> tag that should have a url for
comments, this one is replaced by <wfw:commentRss>.  Both of
these custom tags are defined in a namespace, per the rss spec, but I
still don’t understand why they don’t just use the typical elements for
this information, I’m starting to realize how difficult it would be to
write a robust feed parser (which is not what I want to do).

I’m attempting to use feedparser to parse my rss feeds, and I wanted to
use it in conjunction with IronPython, which I’ve only started playing
around with.  A key feature that I want is the ability to compile
a .py file so that I can consume that file in my c# code.  I’m
looking to compile the feedparser file, and then use that as my parsing
in my project. feedparser is nice because it appears to be very robust
(its got 2000 unit test, whoa!). So hopefully I can get feedparser
working with IronPython in my c# project, that be sweet. :)

Poor Mans .Net

While the debate rages about VSTS pricing, I wanted to talk about kind of the other end of the spectrum, the Express SKUs. 
I’ve been using Visual Web Developer Express and Visual C# Express for
a few months now, with Beta 1 and now Beta 2.  VWD is the shit.
Its awesome, when my trial ran up for Beta 1, I tried to go back to
Dreamweaver, but I only lasted a few days before I installed Beta 2 and
a new copy of VWD.  The intellisense for editing C#/VB in a script
block is great, it makes it much easier to develop some lightweight
pages.

As for C# Express, this is a great product too.  The intellisense
is much improved over VS 2003 and there are some little interface
enhancements that I like better, like when you type the closing bracket
‘{’ it highlights each end of the brackets in a very dark, easy-to-see
way. The only think that I think C# Express is missing, is the ability
to attach to a running process.  I use that feature all the time
in VS 2003, but alas, that functionality isn’t available in the Express
editions.

The best part about the Express products: $50 apiece.  For $100
you can get each of these products, and be well on your way to
developing some great software.  Between these two and SVN, I’m happy as a clam :)

Refactoring to Patterns

I got the opportunity to refactor some code this past week.  We had an .aspx page that streamed an m3u playlist file that would open in Winamp.  We wanted to modify the page so that it would stream an .asx file for Windows Media Player or a playlist for a Flash based mp3 player, based on the user’s preferences.

Since the page wasn’t currently reading any preferences, the code to
create the m3u file was right in the page’s class file.  If I had
wanted to add two more formats, I could have added the code for those
two right into the page as well, but I wanted to make it more flexible
so that we could add even more formats later on, in an easy fashion.

So I created an abstract Playlist class and then made three
subclasses, M3UPlaylist, ASXPlaylist, and FlashPlaylist.  Now all
the logic for creating the appropriate playlist files was contained in
its respective class.  Next, I created a PlaylistFactory class
that had one static method

  • static Playlist CreatePlaylist(PlaylistType type)

So now the code on the page looks something like this:

Playlist list = PlaylistFactory.CreatePlaylist(playlistType);
list.Stream(Request);

Now when we want to add a new playlist type, all we need to do is
create the subclass of Playlist, add the new type to the PlaylistType
enum, and we’re all set, no need to change anything on the page. 
This is whats nice about using a factory pattern like this;  when
you want to add something to the system, you just need to write new
code, not change existing code, which makes for less regression
errors.  Theres nothing really like the satisfaction
of refactoring some code.

OT: Parking Lot Design

This is slightly off topic, but I want to talk about parking lot design.  Parking lots can be the most stressful places to drive for a couple reasons:

  • The idiot in front of you
  • Poor layout

As an example, here is a small shopping center near my house in NE Minneapolis called the The Quarry.  The white circle is a fairly busy stoplight, as the road coming to the light from the south is a freeway exit ramp.  I drive here from the top left corner of the picture on my way to the bank, which is the white square in the bottom right corner.  You’ll notice 2 paths to the bank from the stoplight, one in white and the other in blue.  The path in white is the “normal” way to get to the bank; you enter the parking lot, drive across, and down to the bank.  The route in blue is the route that I take. By avoiding the areas of the parking lot where all the pedestrians are, you can shave about an entire 2 minutes off the driving time.

The picture is from a screenshot of Google Earth. I hope I don’t get sued or anything :)   The image is about 1MB, sorry.

My question is this: why do designers put the entrance to a parking lot at the front of the lot near the stores?  This situation would be much better for everyone involved if the cars entered from the bottom of the picture, this way the cars dont get in the way of the people, and vice-versa.  I realize that there are other considerations, but this is by no means an isolated case. Think about this the next time you’re pulling into the mall parking lot :)   Have a great 4th of July weekend!