[Mono-devel-list] Mono and MySQL
Mike McKay
mike at vdomck.org
Wed Aug 25 07:42:55 EDT 2004
I am trying to use Mono to connect to a MySQL database but I am running
into an error message that according to google many others seem to be
having but not solving. I have had success with Perl (shown at the
bottom of this email), but under Mono I always get this exception:
Unhandled Exception: ByteFX.Data.MySqlClient.MySqlException: Unable to
connect to any of the specified MySQL hosts
Any ideas?? My simple test code follows:
podo OFAC$ cat test.cs
using System;
using ByteFX.Data.MySqlClient;
public class Test{
public static void Main(string[] args){
MySqlConnection myConnection = new MySqlConnection(args[0]);
MySqlCommand myCommand = new MySqlCommand("Select * from test");
myCommand.Connection = myConnection;
myConnection.Open();
MySqlDataReader objReader = myCommand.ExecuteReader();
int nResultCount = 0;
while (objReader.Read())
{
++nResultCount;
}
}
}
(I have tried lots of different connection strings to no avail)
podo OFAC$ mono test.exe "Database=OFAC;UID=root;Host=localhost"
Unhandled Exception: ByteFX.Data.MySqlClient.MySqlException: Unable to
connect to any of the specified MySQL hosts
in <0x00158> ByteFX.Data.MySqlClient.Driver:Open
(ByteFX.Data.MySqlClient.MySqlConnectionString)
in <0x0003c> ByteFX.Data.MySqlClient.MySqlInternalConnection:Open ()
in <0x000ef> ByteFX.Data.MySqlClient.MySqlPool:CreateNewPooledConnection ()
in <0x00214> ByteFX.Data.MySqlClient.MySqlPool:GetPooledConnection ()
in <0x00052> ByteFX.Data.MySqlClient.MySqlPool:GetConnection ()
in <0x00112> ByteFX.Data.MySqlClient.MySqlPoolManager:GetConnection
(ByteFX.Data.MySqlClient.MySqlConnectionString)
in <0x0007c> ByteFX.Data.MySqlClient.MySqlConnection:Open ()
-------------PERL IMPLEMENTATION THAT WORKS------------------------
podo OFAC$ cat test.pl
#!/usr/bin/perl -w
use DBI;
$dataSource="dbi:mysql:OFAC";
$userid="root";
$passwd="";
# make connection to database
$dbh = DBI->connect($dataSource,$userid,$passwd);
#
# prepare and execute query
$query = "SELECT * FROM test";
$sth = $dbh->prepare($query);
$sth->execute();
while ( @row = $sth->fetchrow_array ) {
print "@row\n";
}
podo OFAC$ ./test.pl
42
More information about the Mono-devel-list
mailing list