[Mono-list] Looking for advice on accessing MySQL database
TraLou
louis at traglobal.com
Mon Nov 3 09:41:35 EST 2008
I changed my connection string from "Data Source" to "Server" as Luciano
suggested but that has not fixed the problem. Here is a code sample that
works in Windows but not Mono 2.0.1 for me:
using System.Data;
using MySql.Data.MySqlClient;
Code inside of a method:
string connectionString = "Database=mysql;Server=10.0.1.106;User
ID=user;Password=password;" +
"Pooling=false;Connection Timeout=10;";
DataTable myTable = new DataTable();
using (MySqlConnection myConnection= new
MySqlConnection(connectionString))
{
Console.WriteLine("Opening MySql database connection....");
myConnection.Open();
Console.WriteLine("Connection Opened.");
using (MySqlCommand myCommand = new MySqlCommand("SELECT *
FROM user",myConnection))
{
using (MySqlDataAdapter myAdapter = new
MySqlDataAdapter(myCommand))
{
try
{
myAdapter.Fill(myTable);
}
catch(Exception ex)
{
Console.WriteLine("An exception occurred while
filling the datatable: " + ex.Message);
Console.WriteLine(ex.InnerException);
}
}
}
}
if (myTable.Rows.Count > 0)
{
Console.WriteLine("There are " +
myTable.Rows.Count.ToString() + " rows in the mysql.user table");
}
When MyConnection.Open() is executed I get the following exception:
Unhandled Exception: MySql.Data.MySqlClient.MySqlException: Unable to
connect to any of the specified MySQL hosts. ---> System.Exception:
Exception of type 'System.Exception' was thrown.
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000]
--- End of inner exception stack trace ---
at MySql.Data.MySqlClient.NativeDriver.Open () [0x00000]
at MySql.Data.MySqlClient.Driver.Create
(MySql.Data.MySqlClient.MySqlConnectionStringBuilder settings) [0x00000]
at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000]
--
View this message in context: http://www.nabble.com/Looking-for-advice-on-accessing-MySQL-database-tp20255843p20303964.html
Sent from the Mono - General mailing list archive at Nabble.com.
More information about the Mono-list
mailing list