System.IndexOutOfRangeException - data application block - enterprise library 4.1

Topics: Data Access Application Block
Jun 29, 2009 at 1:02 PM
Edited Jun 29, 2009 at 1:25 PM

I use the Enterprise Library 4.1.

I'm getting this error when  increase the number of users :

System.IndexOutOfRangeException: USER_ID    (random page and random fieldname)
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
at System.Data.SqlClient.SqlDataReader.get_Item(String name)
I Use:
2003 Enterprise Server, .net 3.5,
enterprise library 4.1
MS-SQL Server

I'm getting this error when the number of users increases,
I do not receive this error again when IIS restart

Sample Code:

private Database db = DatabaseFactory.CreateDatabase();

protected void Page_Load(object sender, EventArgs e)
{
   if (!Page.IsPostBack)
   { 
            using (IDataReader grup = YetkiGrupObj.GetGrupKullanici(2,db))
            {
                  while (grup.Read())
                  {
                        ddlGruplar.Items.Add(new ListItem(grup["GRUP_ADI"].ToString(), grup["GRUP_ID"].ToString()));
                  }
            }
      }
}
----- YetkiGrupObj -----
public class YetkiGrupObj
{
    public YetkiGrupObj() {}
    private static DbCommand dbComm = null;
    private static string SqlText;
    public static IDataReader GetGrupBolge(int bolgeId, Database db)
    {
        SqlText = @"select GRUP_ID,GRUP_ADI from YETKI_GRUP 
                    where (BOLGE_ID=@bolgeId or BOLGE_ID=-1)
                    order by GRUP_ID ASC";
        dbComm = db.GetSqlStringCommand(SqlText);
        db.AddInParameter(dbComm, "@bolgeId", DbType.Int32, bolgeId);
        return db.ExecuteReader(dbComm);
    }
    public static   IDataReader GetGrupKullanici(int kullaniciId, Database db)
    {
        SqlText = @"select y.GRUP_ID,y.GRUP_ADI from YETKI_GRUP y ,YETKI_GRUP_KULLANICI k
                    where k.KULLANICI_ID=@kullaniciId and 
					y.GRUP_ID=k.GRUP_ID
                    order by GRUP_ID ASC";
        dbComm = db.GetSqlStringCommand(SqlText);
        db.AddInParameter(dbComm, "@kullaniciId", DbType.Int32, kullaniciId);
        return db.ExecuteReader(dbComm);
    }
}



these records were opened before the same error, but it is not the answer
http://entlib.codeplex.com/WorkItem/View.aspx?WorkItemId=11905

Jun 30, 2009 at 5:34 AM

Hi,

There are some suggestion to get around to this problem, please see these links:

  1. http://www.pcreview.co.uk/forums/thread-1244203.php
  2. http://forums.asp.net/p/744673/745841.aspx
  3. http://social.msdn.microsoft.com/Forums/en-US/csharpgeneral/thread/c4fd4b66-e7d5-4ad9-be0f-a07002a74399
  4. http://forums.devx.com/showthread.php?t=145460

See if these links helps.

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com

Jul 8, 2009 at 11:28 AM
Edited Jul 8, 2009 at 11:30 AM

 

I've looked at the address.

But, I did not find a solution to the problem

I keep getting this errors:

System.IndexOutOfRangeException: USER_ID

Error Message :Cannot find table 0.
Error Trace:
at System.Data.DataTableCollection.get_Item(Int32 index)
   at BugTracker_BugBildirim.btKaydet_Click(Object sender, EventArgs e) in d:\........\BugTracker\BugBildirim.aspx.cs:line 470
   at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
   at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
   at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)


ERROR_MESSAGE:  PROJE_ID    (it's coumn name)
ERROR TRACE:
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at System.Data.SqlClient.SqlDataReader.get_Item(String name)
   at tr.......bugTracker.BugProje.FillBugProjeAlan(IDataReader reader) in d:\......\bugTracker\BugProje.cs:line 154
   at tr.......bugTracker.BugProje.GetById(Int32 projeId, Database db) in d:\.......\bugTracker\BugProje.cs:line 77
   at BugTracker_BugBildirim.ekAlanlar(Int32 projeId) in d:\....\BugTracker\BugBildirim.aspx.cs:line 88
   at BugTracker_BugBildirim.OnInit(EventArgs e) in d:\.....\BugTracker\BugBildirim.aspx.cs:line 82
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

....

DataBinding: 'System.Data.DataRowView' does not contain a property with the name 'OKUNMA'.

Sample Code for this error:

 DataSet

ds = InsanKaynaklariCustom.GetGenelDuyurular(2,db);
grdDuyurular.DataSource = ds;
grdDuyurular.PageIndex = pageNo;
grdDuyurular.DataBind();    // IT'S ERROR LINE

 

InsanKaynaklariCustom.cs
____________________________________________________

using System.Data.Common;
using System.Data;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System;

public class InsanKaynaklariCustom
{
    private static string sqlText;
    private static string orderBy;
    static DbCommand dbComm = null;
   

     public InsanKaynaklariCustom()
    { }


    public static DataSet GetGenelDuyurular(int kullaniciId, Database db)
    {
        sqlText = @"    select
                         gd.DUYURU_ID,
                         gd.BASLIK,
                         gd.DUYURU_OZET,
                         gd.TARIH,
         case (  select count(ID) from IK_GEN_DUYURU_OKUNMA do
                      where do.DUYURU_ID=gd.DUYURU_ID and do.KULLANICI_ID=@kullaniciId)
          when 0 then 'OKUNDU'
          else 'OKUNMADI' end as OKUNMA  
                        from
                         IK_GEN_DUYURU gd,
                         IK_GEN_DUYURU_YETKI gdy,
                         YETKI_HIZMET_KULLANICI yhk
                        where
                            gd.AKTIF = 1
                         and gdy.DUYURU_ID=gd.DUYURU_ID
                         and gdy.HIZMET_ID = yhk.HIZMET_ID
                         and yhk.KULLANICI_ID=@kullaniciId ";
        dbComm = db.GetSqlStringCommand(sqlText);
        db.AddInParameter(dbComm, "@kullaniciId", DbType.Int32, kullaniciId);
        return db.ExecuteDataSet(dbComm);
    }
}

 

I do not receive this error again when IIS restart... 1 or 2 days..

Jul 8, 2009 at 11:55 AM

Example of other error:

ERROR Message: PROJE_ID
Error Trace :
at System.Data.ProviderBase.FieldNameLookup.GetOrdinal(String fieldName)
   at System.Data.SqlClient.SqlDataReader.GetOrdinal(String name)
   at System.Data.SqlClient.SqlDataReader.get_Item(String name)
   at tr.....bugTracker.BugProjeAlanDao.FillBugProjeAlan(IDataReader reader) in d:\...\bugTracker\BugProjeAlanDao.cs:line 154
   at tr.....bugTracker.BugProjeAlanDao.GetById(Int32 projeId, Database db) in d:\...\bugTracker\BugProjeAlanDao.cs:line 77
   at BugTracker_BugBildirim.ekAlanlar(Int32 projeId) in d:\...\BugTracker\BugBildirim.aspx.cs:line 88
   at BugTracker_BugBildirim.OnInit(EventArgs e) in d:\...\BugTracker\BugBildirim.aspx.cs:line 82
   at System.Web.UI.Control.InitRecursive(Control namingContainer)
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

BugBildirim.aspx.cs:
public partial class BugTracker_BugBildirim : System.Web.UI.Page
{
    Database db = DatabaseFactory.CreateDatabase();
   protected void Page_Load(object sender, EventArgs e)
    { ... }
..... 
    private void ekAlanlar(int projeId)
    {
          BugProjeAlan alan = BugProjeAlan.GetById(projeId, db);
          ....
     }
}

 BugProjeAlanDao. cs    :

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using Microsoft.Practices.EnterpriseLibrary.Data;

namespace tr....bugTracker {

public class BugProjeAlanDao {

 private static BugProjeAlan nesne;
 private static string sqlText;
 private static string orderBy;
 static DbCommand dbComm = null;

 public BugProjeAlanDao() {}

 public static BugProjeAlan GetById(int projeId,Database db){
  nesne = new BugProjeAlan();
  sqlText="Select PROJE_ID,BILDIREN_TEL,BILDIREN_TEL_DEGER,BILDIREN_ADI,BILDIREN_ADI_DEGER,BIRIMKATEGORI,BIRIMKATEGORI_DEGER,KONU,KONU_DEGER,MESAJ,MESAJ_DEGER,ONCELIK,ONCELIK_DEGER,DURUMU,DURUMU_DEGER from BUG_PROJE_ALAN where PROJE_ID=@projeId ";
  dbComm = db.GetSqlStringCommand(sqlText);
  db.AddInParameter(dbComm, "@projeId", DbType.Int32, projeId);
  using (IDataReader reader = db.ExecuteReader(dbComm)){
   if(reader.Read()){
    nesne = FillBugProjeAlan(reader);
   }else nesne=null;
  }
  return nesne;
 }
 public static BugProjeAlan FillBugProjeAlan(IDataReader reader){
    nesne = new BugProjeAlan();
   nesne.ProjeId=(Int32)reader["PROJE_ID"];   //THIS IS ERROR LINE... PROJE_ID is PRIMARYKEY IN DATABASE
   nesne.BildirenTel=(Boolean)reader["BILDIREN_TEL"];
   ....
 }
}
}

 

BugProjeAlan.cs:

using System;
namespace tr.....bugTracker {

 [Serializable]
 public class BugProjeAlan:BaseTable {

  public Boolean BildirenTel { get; set; }
   public String BildirenTelDeger { get; set; }
   public Boolean BildirenAdi { get; set; }
   public String BildirenAdiDeger { get; set; }
   public Boolean Birimkategori { get; set; }
   public String BirimkategoriDeger { get; set; }
   public Boolean Konu { get; set; }
   public String KonuDeger { get; set; }
   public Boolean Mesaj { get; set; }
   public String MesajDeger { get; set; }
   public Boolean Oncelik { get; set; }
   public String OncelikDeger { get; set; }
   public Boolean Durumu { get; set; }
   public String DurumuDeger { get; set; }
 
  private Int32 _ProjeId;
  public Int32 ProjeId
  {
   get
   {
    return this._ProjeId;
   }
   set
   {
    this._ProjeId = value;
    base.PrimaryKey = this._ProjeId;
   }
  }
  public BugProjeAlan() {}

  public override string GetName()
  {
   return "BUG_PROJE_ALAN";
  }

  public override string ToString()
  {
   return "[BUG_PROJE_ALAN][KEY="+this._ProjeId.ToString()+"], PROJE_ID="+this.ProjeId.ToString()+", BILDIREN_TEL="+this.BildirenTel.ToString()+", BILDIREN_TEL_DEGER="+this.BildirenTelDeger+", BILDIREN_ADI="+this.BildirenAdi.ToString()+", BILDIREN_ADI_DEGER="+this.BildirenAdiDeger+", BIRIMKATEGORI="+this.Birimkategori.ToString()+", BIRIMKATEGORI_DEGER="+this.BirimkategoriDeger+", KONU="+this.Konu.ToString()+", KONU_DEGER="+this.KonuDeger+", MESAJ="+this.Mesaj.ToString()+", MESAJ_DEGER="+this.MesajDeger+", ONCELIK="+this.Oncelik.ToString()+", ONCELIK_DEGER="+this.OncelikDeger+", DURUMU="+this.Durumu.ToString()+", DURUMU_DEGER="+this.DurumuDeger+"";
  }

 }
}

BaseTable:

using System;

namespace tr.com.assistt
{
    [Serializable]
    public class BaseTable : Object
    {
        public virtual Object PrimaryKey { get; set; }
        public virtual string GetName() { return ""; }
        public BaseTable()
        {
        }
    }
}

Jul 10, 2009 at 8:12 AM

Hi,

One thing I've noticed is that you have the public method public static BugProjeAlan FillBugProjeAlan(IDataReader reader) , that may be called by other codes which passed a datareader which executed against another sqlquery. Could you do a Find All References on that method and make sure that its only being called by the right callers.

Related thread : http://entlib.codeplex.com/Thread/View.aspx?ThreadId=59176

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
entlib.support@avanade.com