[Mono-list] ByteFX.Data.MySqlClient.MySqlStream
Michael Haider
Michael.Haider@hofstaedtler.com
Tue, 18 May 2004 16:53:25 +0200
Hi everybody!
I'm very new to mono and I've found an examplecode on www.go-mono.com
to connect to a mysql database! -- But in my case, as you can see below,
it doesn't work!
Can anyone help me?
Many thanks
Michael!
Here is my code:
using System;
using System.Data;
using ByteFX.Data.MySqlClient;
//using Mono.Data.MySql;
public class Test
{
public static void Main(string[] args)
{
IDbConnection dbcon = new MySqlConnection();
//dbcon = new MySqlConnection(connectionString);
dbcon.ConnectionString = "Server=localhost;dbname=mydb;User
ID=root;Password=4711";
Console.WriteLine("DB is closed");
dbcon.Open();
Console.WriteLine("DB open\n");
IDbCommand dbcmd = dbcon.CreateCommand();
string sql = "SELECT * FROM Custtable";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read())
{
Console.WriteLine("DB read");
}
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
Console.WriteLine("DB closed\n");
}
}
mcs firsttest.cs -r:System.Data.dll -r:ByteFX.Data.dll
Compilation succeeded
mono firsttest.exe
DB is closed
Unhandled Exception: System.NullReferenceException: Object reference
not set to an instance of an object
in <0x0025a> ByteFX.Data.MySqlClient.MySqlStream:get_DataAvailable ()
in <0x00058> ByteFX.Data.Common.MultiHostStream:Read (byte[],int,int)
in <0x00040> ByteFX.Data.MySqlClient.MySqlStream:ReadInt24 ()
in <0x00050> (wrapper remoting-invoke-with-check)
ByteFX.Data.MySqlClient.MySqlStream:ReadInt24 ()
in <0x00062> ByteFX.Data.MySqlClient.Driver:ReadRawPacket ()
in <0x00058> ByteFX.Data.MySqlClient.Driver:ReadPacket ()
in <0x00094> ByteFX.Data.MySqlClient.Driver:Open
(ByteFX.Data.MySqlClient.MySqlConnectionString)
in <0x0003c> ByteFX.Data.MySqlClient.MySqlInternalConnection:Open ()
in <0x000f4>
ByteFX.Data.MySqlClient.MySqlPool:CreateNewPooledConnection ()
in <0x00219> ByteFX.Data.MySqlClient.MySqlPool:GetPooledConnection ()
in <0x00058> ByteFX.Data.MySqlClient.MySqlPool:GetConnection ()
in <0x00116> ByteFX.Data.MySqlClient.MySqlPoolManager:GetConnection
(ByteFX.Data.MySqlClient.MySqlConnectionString)
in <0x00077> ByteFX.Data.MySqlClient.MySqlConnection:Open ()
in <0x00077> Test:Main (string[])