Long Adventure on Mono/MySQL Land!
February 19th, 2009
My head hurts. I'm porting a .NET application to Linux/Mono, and everything was working out fine, except the connectivity to the MySql database. Â I don't have experience as an administrator, so I had a machine set up, I installed mono (after so many time I still have to compile stuff on Linux? Come on!), the application worked, but I had the following issues:
- I could connect to mysql on the production server using
mysql -u user -p
- The application couldn't connect to mysql on the production server (using localhost)
- The application could connect to mysql on another machines
- The same application on another machines could connect to mysql on the production server
At this time I didn't know if the problem was with mono/application or with mysql configuration. So I run a Python script that connected to localhost and it worked fine... Then I downloaded the MySQL .NET provider sources and started to break some rocks (Portuguese expression).
The provider only said something like:
Unable to connect to any of the specified MySQL hosts. ---> System.Exception: Exception of type 'System.Exception' was thrown.
Very usefull information as you can see. After digging up, this exception was being thrown like this:
Really classy material. The actual exception was being thrown by:
-
Socket socket = ...
-
try {
-
socket.EndConnect(ias);
-
} catch (Exception) {
-
socket.Close();
-
return null;
-
}
Oh yeah! What more can I say?
After patching the mysql .net provider with some logging, I had the real exception:
System.Net.Sockets.SocketException: Connection refused
The I did something that I should have done a long time ago:
# telnet localhost 3306 Trying 127.0.0.1... telnet: Unable to connect to remote host: Connection refused
Well, it's proved that it wasn't an application / mono problem. Why did it work with direct mysql on the console and Python? Maybe because they connect using a pipe, instead of the TCP stream that the provider uses, I really don't know.
And wouldn't know how to fix this, but my colleague Paulo Pires came and saved the day. It seams that mysql was configured to use a binding to local named address, and because of that refused connections to localhost.
Related Posts
- The Lack of ASP.NET Events
- Scary model
- ASP.NET WP Recycling When Another Job Runs
- Monitoring NHibernate
- You find out about bad usability...




February 19th, 2009 at 1:42 pm
Logo ao mesmo tempo no Prt.sc estava o post da Andreia Gaita em como usar o apt-get para instalar o moonlight: http://blog.worldofcoding.com/2009/02/moonlight-shining-on-ubuntu.html
Logo o mono tb tem de dar:
sh# sudo apt-get install mono mono-gmcs mono-gac mono-utils monodevelop
February 19th, 2009 at 1:49 pm
Sim, o problema é se a versão que pretendes ainda não está disponÃvel em pacotes, ou então estás numa distro que não tem pacotes…
February 19th, 2009 at 4:16 pm
“I’m porting a .NET application to Linux/Mono”
But… But… I thought there was no need to port stuff between MS’ .NET and Mono…
Sorry, couldn’t resist.
February 19th, 2009 at 4:19 pm
You’d be surprised Carlos.
All the major problems I’m having are related with linux configurations.
February 19th, 2009 at 7:03 pm
The problem is that you’re alone migrating an environment and not just an application code to a platform which administration, apparently you’re not much aware of. As you could see it was pretty easy to solve and no code changes were needed.
Now, getting to a problem is most of the time trickier than finding its solution
Btw, do you want me to send you an Ubuntu CD for installation?
February 20th, 2009 at 2:18 pm
Touché!