You need to tell Nhibernate that you want to use ODP. It won't work by magic :)
Use the OracleDataClientDriver Skickat från min iPad Aug 2, 2011 kl. 21:50 skrev PLen <[email protected]>: > Hello, > > I am using NHibernate 3.0 with an Oracle 11g backend database. My > NHibernate config items include: > > <add key="connection.provider" > value="NHibernate.Connection.DriverConnectionProvider" /> > <add key="connection.dialect" > value="NHibernate.Dialect.Oracle10gDialect" /> > <add key="connection.driver_class" > value="NHibernate.Driver.OracleClientDriver" /> > <add key="proxyfactory.factory_class" > value="NHibernate.ByteCode.Castle.ProxyFactoryFactory,NHibernate.ByteCode.Castle" > / >> > > > From the beginning, I was using the .NET's System.Data.OracleClient > library as my API for connections to the database. I have recently > found out that I need to change and use the Oracle.DataAccess.dll > (ODP.NET) instead. To do this I removed my project's reference to the > System.Data.OracleClient and added the reference Oracle.DataAccess. > In doing so, I needed to make some changes to my code regarding things > like OracleLob objects and OracleParameters. When I run my app, > however, I get errors related to object casting problems which are > related to connection parameters. When I need to call a stored > procedure, for example, I might do something like: > > using (ISession session = NHibernateHelper.OpenSession()) { > using (IDbConnection conn = session.Connection) { > using (IDbTransaction trans = > conn.BeginTransaction()) { > try { > // The initial connection was made. Now > we need to call a stored procedure > // to get the DB username of this user. > IDbCommand cmd = conn.CreateCommand(); > cmd.Transaction = trans; > cmd.CommandType = > CommandType.StoredProcedure; > > IDbDataParameter param = > cmd.CreateParameter(); > param.ParameterName = "USERNAME"; > param.DbType = DbType.String; > param.Size = 100; > param.Direction = > ParameterDirection.ReturnValue; > cmd.Parameters.Add(param); > > cmd.CommandText = > "tmt_common.pkg_tmt_ult.func_get_curr_tmt_user"; > cmd.ExecuteNonQuery(); > > dbname = (String) ((OracleParameter) > cmd.Parameters["USERNAME"]).Value; > > }catch (Exception ex) { > throw new Exception("Error calling package > function for TMT user name: " + ex.ToString()); > } > } > } > } > > > The error is: > > System.InvalidCastException: Unable to cast object of type > 'System.Data.OracleClient.OracleParameter' to type > 'Oracle.DataAccess.Client.OracleParameter'. > > I found that my connection is actually a > System.Data.OracleClient.OracleConnection rather than an > Oracle.DataAccess.Client.OracleConnection even though neither my > project nor my class has a reference to the System.Data.OracleClient > API. > > I must be missing something unless the NHibernate API itself is using > the System.Data.OracleClient and it doesn't matter what I am using, > but that would seem odd. > > Does anyone know what I may be missing or why I am still seeing > System.Data.OracleClient API references? > > Thanks for your time - Peter > > -- > You received this message because you are subscribed to the Google Groups > "nhusers" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/nhusers?hl=en. > -- You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/nhusers?hl=en.
