CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Feb 2001
    Posts
    2,455

    Why is my data reader closing?

    I have a method which retrieves a IDataReader and attempts to load object data using this reader. The problem is, before it gets to the next record using IDataReader.Read(), it is closing. Nothing in my methods closes it......any guesses?

    Code:
            public void DataPortal_Fetch(ProjectInfoListCriteria criteria)
            {
                string query = "SELECT A.*, B.* FROM tbProjects A INNER JOIN tbAwardedProjects B ON A.ProjectID = B.fkProjectID ORDER BY B.ProjectNumber ASC";
                using (InformConnection c = InformConnection.Instance)
                {
                    this.IsReadOnly = false;
    
                    IDataReader rdr = c.ExecuteReader(query);
                    while (rdr.Read())
                    {
                        ProjectInfo info = ProjectInfo.Create();
                        info.ReadIn(rdr);
    
                        ProjectAwardedInfo awarded = ProjectAwardedInfo.Create();
                        awarded.ReadIn(rdr);
    
                        info.AwardInfo = awarded;
                        this.Add(info);
                    }
                    this.IsReadOnly = true;
                }
            }
     
    /// The ProjectInfo.ReadIn(...)
           public void ReadIn(IDataReader rdr)
            {
                LoadProperty(IdProperty, rdr.GetInt32(rdr.GetOrdinal(IdProperty.Name)));
                LoadProperty(NameProperty, rdr.GetString(rdr.GetOrdinal(NameProperty.Name)));
                LoadProperty(CityIdProperty, rdr.GetInt32(rdr.GetOrdinal(CityIdProperty.Name)));
                LoadProperty(CreatedProperty, rdr.GetDateTime(rdr.GetOrdinal(CreatedProperty.Name)));
                LoadProperty(AddressProperty, rdr.GetValue(rdr.GetOrdinal(AddressProperty.Name)));
                LoadProperty(DirectionsProperty, rdr.GetValue(rdr.GetOrdinal(DirectionsProperty.Name)));
                LoadProperty(SitePhoneProperty, rdr.GetValue(rdr.GetOrdinal(SitePhoneProperty.Name)));
                LoadProperty(SiteContactProperty, rdr.GetValue(rdr.GetOrdinal(SiteContactProperty.Name)));
            }
    
    The ProjectAwardedInfo.ReadIn(...)
    
            public void ReadIn(IDataReader rdr)
            {
                LoadProperty(IdProperty, rdr.GetInt32(rdr.GetOrdinal(IdProperty.Name)));
                LoadProperty(NumberProperty, rdr.GetString(rdr.GetOrdinal(NumberProperty.Name)));
                LoadProperty(EstimateIdProperty, rdr.GetInt32(rdr.GetOrdinal(EstimateIdProperty.Name)));
                LoadProperty(AwardDateProperty, rdr.GetDateTime(rdr.GetOrdinal(AwardDateProperty.Name)));
                LoadProperty(ClosedProperty, rdr.GetBoolean(rdr.GetOrdinal(ClosedProperty.Name)));
            }
    As you can see, there is nothing closing my DataReader object. Therefore, why is it being closed?

    Mike B

  2. #2
    Arjay's Avatar
    Arjay is offline Moderator / EX MS MVP Power Poster
    Join Date
    Aug 2004
    Posts
    13,490

    Re: Why is my data reader closing?

    Maybe the connection is being closed? Take a look at InformConnection.Instance (is any other class closing that instance while it's being used?).

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