[Mono-devel-list] MySQL problem

Joe Audette joe_audette at yahoo.com
Sun Feb 27 11:50:17 EST 2005


Hi Paul,

I've seen this many times. MySql is very granular
about who can connect and from what host they can
connect. I would not think there would be any
difference with a c program hitting the same server
with the same connection string using tcp/ip, but if
the connection string is not the same that could be a
difference.

You can grant a user to connect from any host using
syntax like this:
GRANT ALL PRIVILEGES ON dbname.* TO 'user1'@'%'
IDENTIFIED BY 'password1' WITH GRANT OPTION;

Hope that helps,

Joe


--- Paul <paul at all-the-johnsons.co.uk> wrote:

> Hi,
> 
> I've used the MySQL snippet on the mono-project
> website to access an SQL
> database that I have set up.
> 
> The code looks like this (so you don't need to find
> it!)
> 
> using System;
> using System.Data;
> using ByteFX.Data.MySqlClient;
> 
> public class Test
> {
>   public static void Main(string[] args)
>   {
>     string connectionString = "Server=localhost;" +
> "Database=employee;"
> +
>       "User ID=paul;" + "Password=password";
>     IDbConnection dbcon;
>     dbcon = new MySqlConnection(connectionString);
>     dbcon.Open();
>     IDbCommand dbcmd = dbcon.CreateCommand();
>     string sql = "SELECT firstname, lastname " +
> "FROM employee";
>     dbcmd.CommandText = sql;
>     IDataReader reader = dbcmd.ExecuteReader();
>     while(reader.Read())
>     {
>       string FirstName = (string)
> reader["firstname"];
>       string LastName = (string) reader["lastname"];
>       Console.WriteLine("Name: " + FirstName + " " +
> LastName);
>     }
> 
>     reader.Close();
>     reader = null;
>     dbcmd.Dispose();
>     dbcmd = null;
>     dbcon.Close();
>     dbcon = null;
>   }
> }
> 
> This compiles fine, but when I run it, I get the
> following
> 
> Unhandled Exception:
> ByteFX.Data.MySqlClient.MySqlException: #HY000Host
> 'localhost.localdomain' is not allowed to connect to
> this MySQL server
> in <0x000b0>
> ByteFX.Data.MySqlClient.Driver:ReadPacket ()
> in <0x00134> ByteFX.Data.MySqlClient.Driver:Open
> (ByteFX.Data.MySqlClient.MySqlConnectionString
> settings)
> in <0x00039>
> ByteFX.Data.MySqlClient.MySqlInternalConnection:Open
> ()
> in <0x000b1>
>
ByteFX.Data.MySqlClient.MySqlPool:CreateNewPooledConnection
> ()
> in <0x0018a>
>
ByteFX.Data.MySqlClient.MySqlPool:GetPooledConnection
> ()
> in <0x00042>
> ByteFX.Data.MySqlClient.MySqlPool:GetConnection ()
> in <0x000cf>
>
ByteFX.Data.MySqlClient.MySqlPoolManager:GetConnection
> (ByteFX.Data.MySqlClient.MySqlConnectionString
> settings)
> in <0x0004b>
> ByteFX.Data.MySqlClient.MySqlConnection:Open ()
> 
> Now, I have a similar program in C which works fine.
> Is there some
> difference between accessing something in C# than in
> C? I've seen this
> error before, but only when messing about with
> mysqladmin
> 
> TTFN
> 
> Paul
> 
> -- 
> "I like blinking me" - Helen, Big Brother 2
> contestant
> 

> ATTACHMENT part 2 application/pgp-signature
name=signature.asc



=====
joe_audette at yahoo.com
http://www.joeaudette.com
http://www.mojoportal.com



More information about the Mono-devel-list mailing list