Connection Error

Thread is closed for posting
2 posts, 0 answers
  1. Ozcan Oksuz
    Ozcan Oksuz avatar
    9 posts
    Member since:
    Feb 2010

    Posted 30 May 2011 Link to this post

    Hi,

    I am using Telercik Open Access v2011.1.411.2 for database connection.

    In my web service I have defined a DbContext object and I use it in all my transactions.

     

     

     

    public class ExtremeService : IExtremeService
    {
    private static ExtremeModelDbContext m_DbContext = new ExtremeModelDbContext();
    .
    .
    .
    public List<Procedure> ReadAllProcedures()
    {
        return m_DbContext.Procedures.ToList();
    }
    .
    .
    .
    }

    when running transaction sometimes it gives an error such as

    Error executing query: Telerik.OpenAccess.RT.sql.SQLException: There is already an open DataReader associated with this Connection which must be closed first.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
       at OpenAccessRuntime.Relational.fetch.FetchResultImp.Execute()
    SQL:
    SELECT a.`ID` AS COL1, a.`CULTURE` AS COL2, a.`DESCRIPTION` AS COL3, a.`STATUS_CODE` AS COL4 FROM `ris_status_codes` a ORDER BY a.`ID`  Telerik.OpenAccess.RT.sql.SQLException: There is already an open DataReader associated with this Connection which must be closed first.
       at Telerik.OpenAccess.RT.Adonet2Generic.Impl.PreparedStatementImp.executeQuery()
       at OpenAccessRuntime.Relational.conn.PooledPreparedStatement.executeQuery()
       at OpenAccessRuntime.Relational.fetch.FetchResultImp.Execute()

    Is using same DbContext object for every transaction causes this problem?
    Do I have to create new DbContext object for every transaction?
    How can I solve this problem?

    Thanks,
    Burhan Eyimaya

  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 31 May 2011 Link to this post

    Hi Ozcan Oksuz,
    This seems to be a multithreading problem, you are using the same context object in two threads at the same time. I am not sure about you architecture, but if this is a web or application server process you should use a new scope per request or at least per thread. I prefer to have a context or data access layer instance in the master page and dispose it in the masterpage dispose:

    private DataAccess dal;
    public DataAccess Dal
    {
        get
        {
            if (dal == null)
                dal = new DataAccess(connectionString);
            return dal;
        }
    }
    public override void Dispose()
    {
        if (dal != null)
            dal.Dispose();
        dal = null;
        base.Dispose();
    }


    Regards,
    Jan Blessenohl
    the Telerik team
    Q1’11 SP1 of Telerik OpenAccess is available for download; also available is the Q2'11 Roadmap for Telerik OpenAccess ORM.
Back to Top