-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: ADOException: There is already an open DataReader...
PostPosted: Tue Jan 31, 2006 4:09 am 
Newbie

Joined: Sun Jan 15, 2006 11:51 am
Posts: 8
Hi, while trying to run this code I get the ADOException (InnerException):

There is already an open DataReader associated with this Connection which must be closed first.

What can it be? Thanks.

Hibernate version:
1.02

Mapping documents:
Code:
public class Query
{
    public Query()
    {
    }

    public Query(string text)
    {
        this.text = text;
    }

    private long id;
    private string text;

    public string Text
    {
        get { return text; }
        set { text = value; }
    }

    private long Id
    {
        get { return id; }
        set { id = value; }
    }
}

<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" assembly="MyAssembly" namespace="MyNamespace">
  <class name="Query">
    <id name="Id" unsaved-value="0">
      <generator class="native"/>
    </id>   
    <property name="Text" unique="true" length="255"/>   
  </class>
</hibernate-mapping>




Code between sessionFactory.openSession() and session.close():
Code:
using (ISession session = Database.OpenSession()) // Session Factory
{
    ITransaction tr = session.BeginTransaction();
    IEnumerator en = session.Enumerable(
        "select count(*) from Query query where query.Text = ?",
        "text",
        NHibernateUtil.String).GetEnumerator();
    en.MoveNext();
    if ((int)en.Current == 0)
    {
        session.Save(new Query("text"));
    }
    tr.Commit();
}


Full stack trace of any exception that occurs:
at NHibernate.Transaction.AdoTransaction.Commit()
[Skipped]

Name and version of the database you are using:
MySQL Server 5.0 and MySQL Connector Net 1.0.7.


The generated SQL (show_sql=true):
select count(*) as x0_0_ from Query query0_ where (query0_.Text=?p0)
?p0 = 'text'


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 31, 2006 10:56 am 
Newbie

Joined: Thu May 19, 2005 6:04 am
Posts: 14
Location: Glasgow, UK
I get these as well when retrieving objects from the database:

Message: NHibernate.ADOException: Unable to perform find ---> System.InvalidOperationException: There is already an open DataReader associated with this Connection which must be closed first.
at System.Data.SqlClient.SqlCommand.ValidateCommand(String method, Boolean executing)
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Loader.CriteriaLoader.List(ISessionImplementor session)
at NHibernate.Impl.SessionImpl.Find(CriteriaImpl criteria)
--- End of inner exception stack trace ---


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.