-->
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: NHibernate with DB2 - Connection Cast Exception
PostPosted: Fri Jul 05, 2013 6:33 pm 
Newbie

Joined: Fri Jul 05, 2013 6:27 pm
Posts: 2
Gentlemen, good evening.

Im trying to make a connection with my AS400 client (Windows) and my AS400 Server (unix), both V5R4M0, using IBM.DATA.DB2.Dll and IBM.DATA.DB2.iSeries.Dll.

The problem is, NHibernate uses IBM.DATA.DB2.iSeries DLL to make the connections...

But im experiencing the following message: "Unable to cast object of type 'IBM.Data.DB2.iSeries.iDB2Connection' to type 'System.Data.Common.DbConnection'.", When i call BuildSessionFactory (code below):

Code:
var cfg = new NHibernate.Cfg.Configuration();
                    //cfg.Configure();
                   cfg.DataBaseIntegration(
                        x =>
                            {
                                x.ConnectionString =
                                "UserID=CARVALHORA;DataSource=BRRIO04;Password=*****;LibraryList=BRSAP;Initial Catalog=BRSAP;Database=D103be2f";
                                x.Dialect<DB2400Dialect>();
                                x.Driver<DB2400Driver>();
                            });

                   
                    var fluentConfig = Fluently.Configure(cfg)
                                               .Mappings(
                                                   m =>
                                                   m.FluentMappings.AddFromAssembly(Assembly.GetExecutingAssembly()))
                                               .BuildConfiguration();
                   
                    _sessionFactory = fluentConfig.BuildSessionFactory();


Can you guys please, gimme a hand? Im working with .net 4.5 and NHibernate 3 with Fluent, all latest Versions...

Ive tried to connect directly thru the DLL (without NHibernate), and worked:

Code:
String sql = "SELECT * FROM BRSAP.MM_HEADER";
                System.Data.IDbConnection connection = null;
                IDataReader reader = null;
                try
                {
                    connection = new iDB2Connection("UserID=CARVALHORA;DataSource=BRRIO04;Password=******;LibraryList=BRSAP;Initial Catalog=BRSAP;Database=D103be2f");
                    connection.Open();

                    var x = (IDbConnection) connection;
                    IDbCommand command = connection.CreateCommand();
                    command.CommandType = CommandType.Text;
                    command.CommandText = sql;
                    reader = command.ExecuteReader();
                }
                finally
                {
                    try { reader.Close(); }
                    catch (Exception ex) { }
                    try { connection.Close(); }
                    catch (Exception ex) { }
                }


Thanks in advance.


Top
 Profile  
 
 Post subject: Re: NHibernate with DB2 - Connection Cast Exception
PostPosted: Mon Jul 08, 2013 1:07 pm 
Newbie

Joined: Fri Jul 05, 2013 6:27 pm
Posts: 2
anyone?


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.