CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    May 2002
    Posts
    36

    cannot get many records into a DataSet using DataAdapter.Fill

    Code:
    DataSet data = new DataSet();
    SqlDataAdapter adap = new SqlDataAdapter( "SELECT * FROM MyTable WHERE ID BETWEEN 0 AND 500 ORDER BY ID", connection );
    SqlCommandBuilder builder = new SqlCommandBuilder( adap );
    
    adap.Fill( data, "MyTable" ); // ERROR (Exception)
    There are 4 behaviors based on the amount of record I ask to fetch:

    1) If the BETWEEN delta is <= 456 I get my records, no error.

    2) If the delta is “not too big” like 457-500 I get the error:

    An unhandled exception of type 'System.IndexOutOfRangeException' occurred in system.data.dll

    Additional information: Index was outside the bounds of the array.

    3) If the delta is “fairly big” like 1000 I get the error:

    An unhandled exception of type 'System.NullReferenceException' occurred in Unknown Module.
    Additional information: Object reference not set to an instance of an object.

    If I click on “Break” I get the message “There is no source code available for the current location”. This is the only error that takes 2-5 minutes to occur, the others usually takes less than a second.

    4) If the delta is “really big” (10000 and up) I get the error:
    An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll

    Additional information: System error.



    I am starting to believe there is an error in the C# ADO library with memory allocation or something!

    Anyone have an idea of what is going on?

    Thanks,

    Chriss

  2. #2
    Join Date
    May 2002
    Posts
    36

    Going CRAZY!!!

    I tried using a DataReader instead, the ExecuteReader goes fine,
    but I get the SAME exception trying to access the reader values
    when my DateReader iteration reaches the exact SAME position (456).

    example: (code typed realy fast)

    Code:
    DataReader reader = SqlCommand.ExecuteReader();
    
    while( reader.read() )
    {
        // Exception on iteration 456:
        string joe = reader["UserName"];
        // OR
        string joe = reader[2];
        // OR
        reader.IsDbNull( 2 );
    }
    About the "456" amount of MAX records (see first post):
    That number actually changes if I change the Database or
    Table I am reading from, but the number will always be the
    same for a specifdic DB-Table.

    I also got an additional error (than the first 4 mentioned),
    "Network Error : See your network documentation".

    I could re-produce the problem on a small very simple app. and
    on another coders PC (he also have no idea of what is going on).

    I have not been stuck like this on a problem since 3 years ago
    on a bad C++ Stack coruption problem! I am loosing my sanity.

    Any hints or things I should try will make me happy.

    And I am curious, how many records do YOU usually put in a reader?

    Chriss

  3. #3
    Join Date
    May 2002
    Posts
    36

    Detailed Exception Error

    Here is the full member list I get from the Exception object:

    System.IndexOutOfRangeException: Index was outside the bounds of the array.
    at System.Data.SqlClient.TdsParser.ProcessHeader()
    at System.Data.SqlClient.TdsParser.ReadByteArray(Byte[] buff, Int32 offset, Int32 len)
    at System.Data.SqlClient.TdsParser.ReadLong()
    at System.Data.SqlClient.TdsParser.ReadValue(_SqlMetaData md, Int32 length)
    at System.Data.SqlClient.TdsParser.ProcessRow(_SqlMetaData[] columns, Object[] buffer, Int32[] map, Boolean useSQLTypes)
    at System.Data.SqlClient.SqlDataReader.PrepareRecord(Int32 i)
    at System.Data.SqlClient.SqlDataReader.GetValue(Int32 i)
    at System.Data.SqlClient.SqlDataReader.get_Item(String name)

    The last few members can change when I get one of the 5 errors, but it is ALWAYS in "Data.SqlClient.TdsParser". I cannot find any information on this object, except for an obscure reference on an IBM site, about some old format for data transfer.

    Hope this can give light to anyone with an idea!

    Chriss.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured