# Wednesday, May 20, 2009
I noticed that my web app, which makes anywhere from one to many MySQL connections per page was running slowly on my new Windows 7 RC laptop. I used dotTrace to compare the page execution to that of my desktop (which runs the app very quickly) and noticed that it was all the MySQL connections that were taking 10x to 100x as long to execute on the laptop.

After a bunch of troubleshooting I finally determined what was causing the performance problem. It was Nod32 4.0. I couldn't just disable Nod32, though. I had to completely uninstall it to cure the MySQL ODBC slowdown!

With Nod32 4.0 installed, some pages were taking 13 seconds to execute.
Without Nod32 4.0 installed, those same pages were taking less than a second to execute.

I observed this behavior on two systems:
  1. Dell Inspiron E1705 w/ Windows 7 RC x86
  2. Dell Studio 16 XPS w/ Windows 7 RC x64 (happened with both 64-bit and 32-bit ODBC drivers, and with both 3.51 and 5.1 versions of each)
Both systems have Windows 7 so this could be a problem only for Windows 7 users with Nod32 4.0. Maybe it's fine with Vista or some other anti-virus application. I hope this helps someone because it took me FOREVER to figure out it was Nod! I sent their support an email explaining all this. Hopefully they will write back with some info. Aside from this, which is a DEALBREAKER, I love Nod32 :(

Wednesday, May 20, 2009 1:02:25 AM (Central Daylight Time, UTC-05:00)
# Friday, March 06, 2009
You might see OPTION=3 in your MySQL connection string. That number--3 in this case--is the sum of a couple MySQL option flags. In this case, it's
  1. FLAG_FIELD_LENGTH: "Do not Optimize Column Width", and
  2. FLAG_FOUND_ROWS: "Return Matching Rows
So, that option setting allows you to direct your MySQL server to behave in a specific manner for the duration of each connection. A complete table of these options is available in the MySQL 5.0 Reference Manual.

You might also want to use OPTION=67108864, which allows you to execute multiple sql statements in a single MySQL Connector/ODBC batch, separated by semicolons. To keep other things working the way most people expect, just use 67108867, which is all three options combined.

Friday, March 06, 2009 6:00:23 PM (Central Standard Time, UTC-06:00)
# Friday, February 20, 2009
If you've got the Enterprise Library installed and already know how to connect to SQL Server databases, connecting to MySQL databases is not any harder.

One way to do it is to use ODBC. This is what I did:
  1. Go to MySQL.com and download the latest MySQL ODBC connector. As I write this it's 5.1.5. I used the 64-bit version, as I have 64-bit Vista.
  2. Install the ODBC Connector. I chose to use the no-installer version. I just unzipped it and ran Install.bat at an administrator's command prompt. The MSI version probably works fine, but I did it this way back when I installed the 3.51 connector.
  3. Verify the installation by opening your ODBC control panel and checking the Drivers tab. You should see the MySQL ODBC 5.1 Driver listed there. It seems to even co-exist peacefully with the older 3.51 version if you already have that. Additionally it coexists peacefully with the .NET connector if that is installed too.
  4. At this point you will be doing what you've done to connect to a SQL Server database. All you need to know is what to use for a connection string.
  5. Here's what mine looks like:
    <add name="MySqlDatabaseTest" connectionString="server=myservername;database=mydbname;uid=myusername;pwd=mypassword;driver={MySQL ODBC 5.1 Driver};option=3;" providerName="System.Data.Odbc" />
  6. Of course you can set "name" to whatever you want.
  7. If this is your only database, you can set it up as the defaultDatabase like this: <dataConfiguration defaultDatabase="MySqlDatabaseTest"/>
  8. Access your data in your code like you always do! Here's a plain text sql example:
public List<Contact> Contact_SelectAll()
{
    string sql = string.Format(@"
        select
            *
        from
            Contact
    "
);

    List<Contact> contactList = new List<Contact>();
    Database db = DatabaseFactory.CreateDatabase("MySqlDatabaseTest");
    DbCommand dbCommand = db.GetSqlStringCommand(sql);
    using (IDataReader dataReader = db.ExecuteReader(dbCommand))
    {
        while (dataReader.Read())
        {
            Contact contact = new Contact();
            contact.ID = (int) dataReader["ContactID"];
            contact.FirstName = dataReader["ContactFName"].ToString();
            contact.LastName = dataReader["ContactLName"].ToString();
            contactList.Add(contact);
        }
    }

    return
contactList;
}
Another way to do it is to build and use a MySql provider. This guy did that.
I learned how to do this by adapting these instructions for connecting to Access.
Oh, and here are some more MySql Connection String samples.

Friday, February 20, 2009 1:00:42 AM (Central Standard Time, UTC-06:00)