This is a migrated thread and some comments may be shown as answers.

Connection Error

1 Answer 62 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ozcan Oksuz
Top achievements
Rank 1
Ozcan Oksuz asked on 30 May 2011, 12:10 PM
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

1 Answer, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 31 May 2011, 08:47 AM
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.
Tags
General Discussions
Asked by
Ozcan Oksuz
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Share this question
or