[Mono-aspnet-list] My sql connectivity with asp.net

jmalcolm malcolm.justin at gmail.com
Thu Apr 7 10:48:20 EDT 2011

You are probably going to have to post the error you are getting (and the
stack trace that you are currently disgarding) to get any expert feedback.

That said, there are a couple of things from my experience that I would
point out:

You seem to be using ODBC. I would recommend you use the MySQL connector for
.NET (MySql.Data.dll) which is available at their website:


It sounds like perhaps you do not have ODBC support installed. The .NET
connector is 100% managed and does not have any C-lib dependencies (that I
am aware of). You will need to be MySql.Data.dll where your app can see it.
You could install it in the GAC but I prefer to put it into the /bin
directory of my web app. Make sure that the filename has the correct casing
so that Ubuntu will see it.

When you are using the .NET connector, I believe you should be using the
expanded list of your parameter names (@firstname, etc) instead of

I realize this is just a test case sample but in I would also recommend you
look into the "using" keyword as an alternative to a try/catch block for
database resources. Your current code would leave the database connection
open if there was an exception executing the command.

There are also a couple of things you could do to make your post more
readable for people who might help. One would be consistency with your
casing. It is not clear to me why ConnectionString would be capitalized but
myConnection would not be for example. In .NET code, typically neither would
be as they are both object instances. Ditto for CommandText and myCommand.

If you are using C# 3.0 or newer, which I am sure you are, you could also
use 'var' to reduce some of the noise. For example:

OdbcConnection myConnection = new OdbcConnection(ConnectionString);

could be written as...

var myConnection = new OdbcConnection(connectionString);

It is a small point but it makes a big difference for me, especially when
the formatting, indentation, and alignment of your post gets pushed out of

There is also the small matter of doing Response.Write and direct database
connections (with hard-code connection names no less) right in an event
handler. None of that is helping you get your problem fixed though. I am
sure this is just a test case or example anyway.

I mean no offence if all these things are known to you. I am only trying to
be helpful.

Give the .NET connector for MySQL a try and report back.

View this message in context: http://mono.1490590.n4.nabble.com/My-sql-connectivity-with-asp-net-tp3432540p3433635.html
Sent from the Mono - ASP.NET mailing list archive at Nabble.com.

More information about the Mono-aspnet-list mailing list