Forty Cal

About Me

My photo
Fort Worth, TX, United States

Friday, July 6, 2007

Export Tables From MS Access to SQL Server

I had a couple tables in an old MS Access 2003 database that I wanted to convert to SQL Server 2005, so I tried to use the Upsizing Wizard for the first time ever. I don't know why exactly, but I could never get it to work. Kept giving me some SQL error that didn't make sense. I wasn't looking forward to recreating the tables from scratch in SQL Server, so I dug around a little more and discovered that you can right-click on a table and Export to any ODBC database. Score!

If you want to do this yourself, you'll first need to create an ODBC Data Source on your machine which connects to your SQL Server. (If you don't know how to do this, just do a web search.)

Once you have an ODBC Data Source, open your Access database, right-click, and choose Export:


Choose ODBC as the data source:



Type in the name of the new table on SQL Server (it will default to being created under dbo):



Choose the ODBC data source you want to connect to (this could be Oracle, SQL Server 2000, IBM DB2, or any other database):



Depending on your ODBC configuration, it may ask you to login:



Once you click next, it won't actually tell you anything (some feedback would have been nice), but if you go out to your SQL Server database, you should see the new table. And the nice thing is, it preserves all your data types and PKs.

Replace First Occurrence of a String in C#

I had a need to replace only the first occurrence of a substring within a string, and C# doesn't seem to have a way of doing this with the out-of-the-box String methods. So, I rolled my own:

public static string ReplaceFirstOccurrence(string original, string oldValue, string newValue)
{
    if (String.IsNullOrEmpty(original))
        return String.Empty;
    if (String.IsNullOrEmpty(oldValue))
        return original;
    if (String.IsNullOrEmpty(newValue))
        newValue = String.Empty;
    int loc = original.IndexOf(oldValue);
    return original.Remove(loc, oldValue.Length).Insert(loc, newValue);
}

If you're interested, here is the test case for this method:
[TestClass]
    public class ReplaceFirstOccurrenceTest
    {
        [TestMethod]
        public void TestReplaceFirstOccurrence()
        {
            Assert.AreEqual("", StringUtil.ReplaceFirstOccurrence(null, null, null));
            Assert.AreEqual("", StringUtil.ReplaceFirstOccurrence("", "", ""));
            Assert.AreEqual("Th is what is right.",
                StringUtil.ReplaceFirstOccurrence("This is what is right.", "is", null));
            Assert.AreEqual("Th is what is right.",
                StringUtil.ReplaceFirstOccurrence("This is what is right.", "is", ""));
            Assert.AreEqual("This is what is right.",
                StringUtil.ReplaceFirstOccurrence("This is what is right.", null, ""));
            Assert.AreEqual("This is what is right.",
                StringUtil.ReplaceFirstOccurrence("This is what is right.", "", "stuff"));
        }
    }

Wednesday, July 4, 2007

The following module was built either with optimizations enabled or without debug information

I was getting this annoying message every so often when I would build my solution in Visual Studio 2005.

I'm not really sure what it changed (or why I was getting the message), but this fixed it for me:

  • On the VS 2005 menu, go to Tools => Options => Debugging => General.
  • Uncheck: 'Enable Just My Code (Managed Only)'
If anyone knows why you get this message in the first place, I'd be interested in knowing.

Sunday, June 24, 2007

Get LoadPostData to fire on Web Custom Control with ASP.NET 2.0 (C#)

I was trying to write my first web custom composite control and for the life of me, I couldn't get the LoadPostData event to fire. After wrestling with this for a day, I stumbled onto this site that laid it down step-by-step. After checking these things, it worked.

Here's the article for reference:

LoadPostData doesn't fire

I've struggled with this a couple of times, but I think I've got it figured out now. When I implement IPostBackDataHandler on my ASP.NET server control, my LoadPostData event doesn't get hit. This is because I haven't read the MSDN documentation properly.

For a ASP.NET server control to handle postback data correctly, it has to meet the following criteria.
1. The class must implement IPostBackDataHandler.
2. Implement LoadPostData to load the form data.
3. The name (not the ID!) of one of the html controls it renders must exactly match the UniqueID of the control (I always forget this one).
4. Implement RaisePostDataChangedEvent.

Not too tricky.

Map My Run

Carla and I have been jogging around our neighborhood for the last month or so. A friend showed us this cool website called mapmyrun.com, so I started mapping out our runs. So far, we only have two, but I'll be adding more as we get more used to running.

Our runs

I'm done with DRM.

After a frustrating attempt to legally purchase and download a Breaking Benjamin song on Yahoo! Music, I've finally decided that I'm done with music that uses Digital Rights Management (DRM) protection. I don't know what I'm going to do as far as getting new music (maybe go back to buying CDs), but I've made up my mind about not supporting DRM.

Here's a funny (but true) video by the executive editor of ZDNet about DRM:

D.R.M. = C.R.A.P.

His video summarizes exactly how I feel about it, too, and I'm going to vote with my wallet and not buy anymore C.R.A.P.

Sunday, June 3, 2007

Visit to the Pistol Range

Carla and I went to On Target shooting range in Fort Worth to get some practice time with our Glocks. Carla's pistol is a G17 and mine is a G27, but today I was primarily firing 357 SIG and a little bit of 9mm through my gun.

Here are the pics:

Blog Archive