Archive for May, 2006

Data Slinging

In order to move my blog posts from Community Server to Wordpress, I needed to move content from a Sql Server database to MySql.  I hadn’t dealt with MySql for nearly a year at this point, so I went about checking out my options as far as slinging data between these different databases.

I came across this (new?) tool from MySql called the MySql Migration Toolkit.  The toolkit is supposed to allow you to connect to various other databases and move your data into a specified MySql database, as of right now it supports Sql Server, Access, and Oracle.

The interface for the toolkit is very nice, along the lines of the MySql Query Browser and the MySql Administrator.  MySql has really impressed me with how nice their tools have come to look, and the ease of use and installation is second to none.  However, I found the toolkit to be a little rough around the edges.  It took me about a dozen tries until I could finally move my data the way I wanted to, and I couldn’t get it to connect to Sql 2005 at all, I had to move the data to Access before I could get to it.  The real thing that was annoying though, was that it didn’t move the content of my blog posts over correctly, which is admittedly, an easy thing to screw up.

I ended up putting my posts and comments into a CSV file and then importing them using SUS (straight-up-sql), via phpAdmin.  It was actually rather easy that way, and ironically, that was the method I was trying to avoid by getting the migration toolkit.  Sometimes the old school way of doing things can be the easiest I guess.

Uh, AndAlso?

Since I’ve been doing some VB.NET lately in my current project I have noticed some of the differences between VB and C# that I may not have noticed before.

In C# this code is kosher:

string s = null;
if (s != null && s.Length > 0)
{
/* do stuff */
}

But in VB, this will throw a NullReferenceException.

Dim s As String = Nothing
if ((Not s = Nothing) And s.Length > 0) Then
‘ Do stuff
End If

The exception gets thrown because the And keyword still processes both expressions of the ‘If’ statement, even though after the first expression has been found to be false, the ‘If’ statement CAN’T be true. If you want to get an optimized ‘If’ statement, you have to use the really cool ‘AndAlso’ keyword, like this:

Dim s As String = Nothing
if ((Not s = Nothing) AndAlso s.Length > 0) Then
‘ Do stuff
End If

The code above will work with no exception. I think the reason that the behavior of the ‘And’ keyword was left this way for backward compatibility, although I can only come up with one pretty weak scenario where this would matter, if you were doing something like this:
Dim myObj as MyObject = New MyObject()
Dim s as String = String.Empty
if (s = Nothing And myObj.DoSomethingReallyImportantHere() ) Then
‘ Do stuff
End If

By using the ‘And’ keyword, seasoned VB people would expect the .DoSomethingReallyImportantHere() function to always get called, even though the first expression of the ‘If’ statement already ensured that the combined expression would be false. So to preserve backward compatibility we now have ‘AndAlso’, what a joy.

UPDATE: I’m a moron, see Joe’s comment below

Double check your error settings

If you’re a company that offers web products & services, you should really make sure your potential customers NEVER see this page, its quite bad for business.

Errorclipped