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 :-)

Leave a Comment

Name: (Required)

E-mail: (Required)

Website:

Enter my name (ben) in this box, so I know you're a human.

Comment: