[Mono-list] FW: MySql Connector

Damien Churchill damien.churchill at ukplc.net
Fri Oct 20 06:54:02 EDT 2006

>From the mysql site:
public DataSet SelectRows(DataSet dataset,string connection,string
    MySqlConnection conn = new MySqlConnection(connection);
    MySqlDataAdapter adapter = new MySqlDataAdapter();
    adapter.SelectCommand = new MySqlCommand(query, conn);
    return dataset;

I've just modified my console program to resemble that. Receive the same

It works fine if it's just a 'SELECT * FROM table;' but when I call that
procedure it falls over. This is what's puzzling me.

-----Original Message-----
From: Bradley, Peter [mailto:pbradley at uwic.ac.uk] 
Sent: 20 October 2006 11:48
To: Damien Churchill; Mono-list at lists.ximian.com
Subject: RE: [Mono-list] FW: MySql Connector

If I remember correctly, if you use a DataAdapter you don't have to
worry about opening or closing the connection.  The adapter does that
for you: but if you do open() the connection, you absolutely must
close() it.

With a DataReader, you must both open and close the connection.



-----Original Message-----
From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Damien
Sent: 20 October 2006 11:41
To: Mono-list at lists.ximian.com
Subject: [Mono-list] FW: MySql Connector

Yeah I would have thought that as well, but that's on a single
statement. I wrote a simple console program to test it.

using System;
using System.Data;
using System.Collections.Generic;
using System.Text;
using MySql.Data.MySqlClient;
namespace mysqltest
    class Program
        static void Main(string[] args)
            string connectionString =
                "Server=***.***.***.***;" +
                "Database=********;" +
                "User ID=********;" +
                "Password=********;" +
                "Allow Zero Datetime=true";

            MySqlConnection dbConn = new

            MySqlDataAdapter da = new MySqlDataAdapter();
            MySqlCommand dbcmd = dbConn.CreateCommand();
            dbcmd.CommandText = "CALL spUserPrivileges(1);";
            DataSet ds = new DataSet();

            da.SelectCommand = dbcmd;

            dbcmd = null;
            da = null;


That's all it does. It works fine with other selects, and other stored
procedures, just not that one.

-----Original Message-----
From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Robert Jordan
Sent: 20 October 2006 11:28
To: Mono-list at lists.ximian.com
Subject: Re: [Mono-list] MySql Connector

Damien Churchill wrote:
> I was wondering has anyone else has experienced this:
> Unhandled Exception: MySql.Data.MySqlClient.MySqlException: There is
> already an open DataReader associated with this Connection which must
> closed first.
>   at MySql.Data.MySqlClient.MySqlCommand.CheckState () [0x00000] 
>   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader
> behavior) [0x00000] 
>   at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader () [0x00000] 
>   at (wrapper remoting-invoke-with-check)
> MySql.Data.MySqlClient.MySqlCommand:ExecuteReader ()
>   at MySql.Data.MySqlClient.Driver.ReportWarnings () [0x00000]
> I receive this error when trying to execute a stored procedure (other
> SQL statements work fine, even other stored procedures). It works fine
> on windows with .NET but on mono (windows or linux) I receive that
> error.

You're not closing the previous reader. It doesn't fail on MS.NET
because their garbage collector is probably disposing the reader
faster than Mono's.


Mono-list maillist  -  Mono-list at lists.ximian.com
Mono-list maillist  -  Mono-list at lists.ximian.com

More information about the Mono-list mailing list