[Mono-list] WebControls.DataGrid and DataReader problems

Francisco Figueiredo Jr. fxjrlists at yahoo.com.br
Wed Aug 31 22:41:16 EDT 2005


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1



Hi all,


I'm getting some problems when using WebControls.DataGrid and a
DataReader as datasource.

The problem seems to be with the enumerator getting past the size of
reader when reading values to fill a grid.

I received a report from Jan Waiz about getting exceptions when using an
NpgsqlDataReader when using a grid and a setting PageSize and
VirtualItemCount properties.

When using a dataset as datasource this problem doesn't appear.


Sample test case:


//  THIS IS THE CODE THAT WORKS !!!!!!!!!!!!!!!!!!!!!!!!!
      //  Dont forget to disable above Source when trying this :-)
/*
      //  Get a Connection...
      NpgsqlConnection oConn = new NpgsqlConnection();
      //  ...with a guilty Connection-String
      oConn.ConnectionString = "DRIVER={PostgreSQL};" +
                               "SERVER=127.0.0.1;" +
                               "UID=npgsql_tests;" +
                               "DATABASE=npgsql_tests";
      oConn.Open();

      DataSet oDSet = new DataSet();

      DataAdapter oAdap = new NpgsqlDataAdapter( "SELECT * FROM
MyTable", oConn );
      oAdap.Fill( oDSet );

      // Normaly via a Count-Statement.
      DataGrid1.VirtualItemCount = 3;
      DataGrid1.PageSize = 10;
      //  Assign and bind Datareader
      DataGrid1.DataSource = oDSet;
      DataGrid1.DataBind();

      //  Finish. Close what has to be closing...
      oConn.Close();

=========================================================


  //  THIS IS THE CODE THAT DOESNT WORK
      //  Dont forget to disable below Source when trying this :-)

            //  Get a Connection...
                  Npgsql.NpgsqlConnection oConn = new
Npgsql.NpgsqlConnection();
                  //  ...with a guilty Connection-String
      oConn.ConnectionString = "DRIVER={PostgreSQL};" +
                               "SERVER=127.0.0.1;" +
                               "UID=npgsql_tests;" +
                               "DATABASE=npgsql_tests";

                  oConn.Open();
                  //  Get a Command-Object
      Npgsql.NpgsqlCommand oCmnd = oConn.CreateCommand();
      //  Assign Statement
      oCmnd.CommandText = "SELECT * FROM MyTable";

      //  Get a Datareader
      Npgsql.NpgsqlDataReader oRead = oCmnd.ExecuteReader();

      // Normaly via a Count-Statement.
      DataGrid1.VirtualItemCount = 3;
      DataGrid1.PageSize = 10;
      //  Assign and bind Datareader
      DataGrid1.DataSource = oRead;
      DataGrid1.DataBind();

      //  Finish. Close what has to be closing...
      oRead.Close();
                  oConn.Close();



The only difference between those tests are the datasource type.


This is the stack trace he receives:

//  What happens. If PageSize is larger than VirtaulItemCount, following
  //  Runtime-Error happens when running in Mono.
  //    System.InvalidOperationException: DataReader positioned beyond
end of result set.
  //    in <0x00072> Npgsql.NpgsqlDataReader:CheckHaveRow ()
  //    in <0x00029> Npgsql.NpgsqlDataReader:GetValues (System.Object[]
Values)
  //    in <0x00031> System.Data.Common.DbEnumerator:get_Current ()
  //    in <0x00016>
System.Web.UI.WebControls.PagedDataSource+PrivateIEnumeratorEnumerator:get_Current
()
  //    in <0x006e2>
System.Web.UI.WebControls.DataGrid:CreateControlHierarchy (Boolean
useDataSource)
  //    in <0x0003f>
System.Web.UI.WebControls.BaseDataList:OnDataBinding (System.EventArgs e)
  //    in <0x00023> System.Web.UI.WebControls.BaseDataList:DataBind ()
  //    in <0x000b7> NpgTest.Default:Page_Load (System.Object sender,
System.EventArgs e)
  //    in (wrapper delegate-invoke)
System.MulticastDelegate:invoke_void_object_EventArgs
(object,System.EventArgs)
  //    in <0x0005c> System.Web.UI.Control:OnLoad (System.EventArgs e)
  //    in <0x00026> System.Web.UI.Control:LoadRecursive ()
  //    in <0x00212> System.Web.UI.Page:InternalProcessRequest ()
  //    in <0x000af> System.Web.UI.Page:ProcessRequest
(System.Web.HttpContext context)
  //    in <0x00233>
System.Web.HttpApplication+ExecuteHandlerState:Execute ()
  //    in <0x0007c>
System.Web.HttpApplication+StateMachine:ExecuteState (IStateHandler
state, System.Boolean readysync)



After checking Npgsql logs, it seems that return value of
NpgsqlDataReader.Read() isn't being checked when it returns false when
there is no more row to be read. As this seems to be ignored, code tries
to read data again and NpgsqlDataReader throws an exception saying there
is no more data to read.


I tested that code with latest svn code and I could see that it is
already fixed.

I just wanted to confirm if this was really a bug with last released
code as with 1.1.8.3 this problem still exists.

Thanks in advance.



- --
Regards,

Francisco Figueiredo Jr.
Npgsql Lead Developer
http://gborg.postgresql.org/project/npgsql
MonoBrasil Project Founder Member
http://monobrasil.softwarelivre.org


- -------------
"Science without religion is lame;
religion without science is blind."

                  ~ Albert Einstein
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.6 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org

iQEVAwUBQxZqTP7iFmsNzeXfAQL4owf/fyWBrem6m77ouo1SVFYgoPU7AV0jrHp0
mP+ipRc1y6agf+gu+tJLuknOwiR9xavGY3zuXIfk2+L4DLg8Yrp5spF/tKUZkCfu
dMutvevFP4IZDySUzFUn5Ydnp8osoFzxas7BH1Gq1joeChmopa+1aXDqSn6hRW1z
yRxEim/fpzEqj7viaTM7S/vcucRwfqyBPDQcdLqxOUUZYaNjlcaN0/5Rvf2pf6mp
4+fP1N0WLELuxJ/Z0tNwi0dtPPaUKEfbNaJgIgEFAoQ0QXMz3Nca0ag7V5lZM4z2
JjvixBptZO/+Q/ND4jY8EWMed66FyUFPn5gTfRMtV9sT/Aztb001rw==
=zPJo
-----END PGP SIGNATURE-----

	
	
		
_______________________________________________________ 
Yahoo! Acesso Grátis - Internet rápida e grátis. 
Instale o discador agora! http://br.acesso.yahoo.com/


More information about the Mono-list mailing list