[Mono-list] FW: MySql Connector
Bradley, Peter
pbradley at uwic.ac.uk
Fri Oct 20 08:03:51 EDT 2006
Pass, Damien. That has me beat. I hope someone else will be able to
help.
Peter
-----Original Message-----
From: Damien Churchill [mailto:damien.churchill at ukplc.net]
Sent: 20 October 2006 11:54
To: Bradley, Peter; Mono-list at lists.ximian.com
Subject: RE: [Mono-list] FW: MySql Connector
>From the mysql site:
public DataSet SelectRows(DataSet dataset,string connection,string
query)
{
MySqlConnection conn = new MySqlConnection(connection);
MySqlDataAdapter adapter = new MySqlDataAdapter();
adapter.SelectCommand = new MySqlCommand(query, conn);
adapter.Fill(dataset);
return dataset;
}
I've just modified my console program to resemble that. Receive the same
error.
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.
HTH
Peter
-----Original Message-----
From: mono-list-bounces at lists.ximian.com
[mailto:mono-list-bounces at lists.ximian.com] On Behalf Of Damien
Churchill
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
MySqlConnection(connectionString);
dbConn.Open();
MySqlDataAdapter da = new MySqlDataAdapter();
MySqlCommand dbcmd = dbConn.CreateCommand();
dbcmd.CommandText = "CALL spUserPrivileges(1);";
DataSet ds = new DataSet();
da.SelectCommand = dbcmd;
da.Fill(ds);
dbcmd = null;
da = null;
Console.WriteLine(ds.Tables[0].Rows.Count);
Console.Read();
}
}
}
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
be
> closed first.
> at MySql.Data.MySqlClient.MySqlCommand.CheckState () [0x00000]
> at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader
(CommandBehavior
> 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.
Robert
_______________________________________________
Mono-list maillist - Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
_______________________________________________
Mono-list maillist - Mono-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-list
More information about the Mono-list
mailing list