Bug #12088 DataSet can't work with stores procedures
Submitted: 21 Jul 2005 19:39 Modified: 2 Aug 2005 20:41
Reporter: Julio Valencia Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S1 (Critical)
Version:1.0.4 OS:Windows (Windows XP)
Assigned to: Reggie Burnett CPU Architecture:Any

[21 Jul 2005 19:39] Julio Valencia
Description:
I'd created a Table
CREATE TABLE `pdb` (
  `Id` int(11) NOT NULL auto_increment COMMENT 'Pri',
  `Tabla` varchar(90) character set utf8 collate utf8_bin NOT NULL default 'No',
  PRIMARY KEY  (`Id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
I
The following stored procedure was create in the Test dataBase:

DELIMITER $$

CREATE PROCEDURE `test`.`LeerDatos`()
BEGIN
SELECT * FROM pdb;
END$$

DELIMITER ;

then, in a ASP.NET application i'd declared a connection variable, command variable and dataadapter variable to invoke the stored procedure in the following way.

 Dim cnn As New MySql.Data.MySqlClient.MySqlConnection("Database=Test;Data Source=localhost;User Id=root;Password=root")
 cnn.Open()
 Dim cm As New MySql.Data.MySqlClient.MySqlCommand("LeerDatos")
 cm.CommandType = CommandType.StoredProcedure
 Dim da As New MySql.Data.MySqlClient.MySqlDataAdapter
 da.SelectCommand = cm
 da.SelectCommand.Connection = cnn
 Dim ds As New DataSet("Resultados")
 da.Fill(ds)
 cnn.Close()
 d.DataSource = ds
 d.DataBind()

and the error is:

MySql.Data.MySqlClient.MySqlException: Invalid attempt to access a field before calling Read().  This error occurs at the da.fill(ds) line.

How to repeat:
Everytime you traying uses a stored procedure with dataAdapter.
[25 Jul 2005 7:14] Vasily Kishkin
Could you please explane me why you close connection before d.DataBind() ?

 ..
 ..
 da.Fill(ds)
 cnn.Close()  -- here
 d.DataSource = ds
 d.DataBind()
[27 Jul 2005 21:18] Julio Valencia
According with Platform .NET concepts, is unnecessary keep the connection open to bind the date to the control. In fact that is one advantage of the dataset.

If you need more information let me know please.  For a detailed information visit http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpguide/html/cpconovervie...

Thanks 

Julio Valencia P.
MCP Windows Forms Application And ASP.NET Application.
[29 Jul 2005 8:24] Vasily Kishkin
Thanks for advice.
I was able to repeat the bug.
Test case is attached.
[29 Jul 2005 8:24] Vasily Kishkin
Test case

Attachment: 12088.zip (application/x-zip-compressed, text), 5.47 KiB.

[2 Aug 2005 20:41] Reggie Burnett
This has been fixed.  The error was related to calling a stored procedure with either whitespace in the paramtere list or no parameters.  See the following bug:
Bug #11542  Call to Stored Procedure throws exception when SP has no arguments