0

i am using for develop my application Visual Estudio 2010 c#, nhibernate queryover, silverlight 5, in this part all work fine in the data access part i use this :

using (var session = NHibernateFactory.OpenSession())
{
   ClassAlias ca = null;
   var x = session.QueryOver<SomeClass>()
           .Where(root=>root.SomeField > somefield)
           .SelectList(list=>list
            .Select(root=>root.SomeField1).WithAlias(()=>ca.SF1)
             ...
            .Select(root=>root.SomeFieldN).WithAlias(()=>ca.SF2)
            )
            .UnderlyingCriteria.SetResultTransformer(
                        Transformers.AdvanceEntityMapTransformer<ClassAlias>())
                    .List<ClassAlias>();

}

All the data access are select statement, so the problem is when i do publish my application into linux environment with mono, then i start get this intermittent error:

16:51:45.488 [Threadpool worker] ERROR NHibernate.Transaction.AdoTransaction - Begin transaction failed
System.NotImplementedException: The requested feature is not implemented.
  at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction transaction) [0x00000] in <filename unknown>:0
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
  at NHibernate.Connection.DriverConnectionProvider.GetConnection () [0x00000] in <filename unknown>:0

this log is from the nhibernate general log file, the think is that i dont find whow to fix it, any help will be realy wellcome

i add a custom log for capture the exception and make sure that this exception in nhibernate is the cause of my query fail, that is the case and this is the exception:

 ERROR serverAppLog - custom error message
NHibernate.Exceptions.GenericADOException: could not execute query
[ SELECT this_.list_id as y0_, this_.list_name as y1_ FROM vicidial_lists this_ ]
[SQL: SELECT this_.list_id as y0_, this_.list_name as y1_ FROM vicidial_lists this_] ---> System.NotImplementedException: The requested feature is not implemented.
  at MySql.Data.MySqlClient.MySqlConnection.EnlistTransaction (System.Transactions.Transaction transaction) [0x00000] in <filename unknown>:0
  at MySql.Data.MySqlClient.MySqlConnection.Open () [0x00000] in <filename unknown>:0
  at NHibernate.Connection.DriverConnectionProvider.GetConnection () [0x00000] in <filename unknown>:0
  --- End of inner exception stack trace ---
  at NHibernate.Loader.Loader.DoList (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters) [0x00000] in <filename unknown>:0
  at NHibernate.Loader.Loader.ListIgnoreQueryCache (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters) [0x00000] in <filename unknown>:$
  at NHibernate.Loader.Loader.List (ISessionImplementor session, NHibernate.Engine.QueryParameters queryParameters, ISet`1 querySpaces, NHibernate.Type.IType[] resu$
  at NHibernate.Loader.Criteria.CriteriaLoader.List (ISessionImplementor session) [0x00000] in <filename unknown>:0
  at NHibernate.Impl.SessionImpl.List (NHibernate.Impl.CriteriaImpl criteria, IList results) [0x00000] in <filename unknown>:0

1 Answers1

1

If you're using System.Transactions / TransactionScope (which it seems from your stack trace you are), then I suspect this is because the transaction is being escalated to a distributed transaction (ie. DTC).

Typically this happens if you try to access two different transactional resources within the same TransactionScope - eg. two different databases (or the same database but the connection strings differ), or MSMQ and a database.

The problem is that most MySql drivers do not support DTC - and that's what causes this exception to be thrown. You have a number of options:

  1. Figure out why it's escalating and find a way to avoid this (best for performance if possible - DTC is relatively slow)
  2. Fix the MySql driver to either escalate or not enlist (I'm not sure of the ramifications of the latter)
  3. I have heard rumours that there are some commercial MySql drivers that do support DTC - check with Google
  4. Possibly use ODBC, see Distributed transactions between MySQL and MSSQL (I have not tried this, but it seems to be possible)
  5. Use Sql Server :)
Community
  • 1
  • 1
Martin Ernst
  • 5,629
  • 2
  • 17
  • 14
  • thank you very much for your reply, I find it really useful. I will try to figure out where I'm causing DTC context and will try to avoid it. I hope to achieve in any case will let you know – Guillermo F. Lopez Oct 12 '12 at 14:31
  • I can not find anything that would cause this, at least not compiled, could be causing my application consists of (a class that is using NHibernate to fetch data from the database (mysql) and provides them to the application of silverligth through a wcf) is called as a control within a PHP page? – Guillermo F. Lopez Oct 12 '12 at 19:49
  • Check for the TransactionFlowAttribute and OperationBehavior(TransactionScopeRequired = true) on your WCF service – Martin Ernst Oct 14 '12 at 08:40