I have written a small program to insert some records into an oracle database. If I make a direct connection to oracle, the program runs fine. However, if I try to connect via ODBC the program does not work. It is able to perform a SELECT
statement, but not an INSERT
statement.
When I was developing the program, I was using these settings in my NHibernate configuration:
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.connection_string">
Data Source=192.168.1.43:1521/xxxx;User ID=xxxx;Password=xxxx
</property>
<property name="connection.driver_class">
NHibernate.Driver.OracleClientDriver
</property>
<property name="hbm2ddl.keywords">auto-quote</property>
With these settings the program works.
For production, I am using these settings:
<property name="connection.provider">
NHibernate.Connection.DriverConnectionProvider
</property>
<property name="dialect">NHibernate.Dialect.Oracle10gDialect</property>
<property name="connection.connection_string">
DSN=TRUST;Server=oracle;UID=xxxx;PWD=xxxx
</property>
<property name="connection.driver_class">
NHibernate.Driver.OdbcDriver
</property>
<property name="hbm2ddl.keywords">auto-quote</property>
Using the production settings, I get this exception when I try to insert data:
NHibernate.Exceptions.GenericADOException: could not insert: [Domain.Phoenix.StructureAssign#35159][SQL: INSERT INTO STRUCTURE_ASSIGN (CLIENT_ID, STRUCTURE, NAME_CODE, START_DATE, FINISH_DATE, MEMO_NUMBER, ALTERNATE, ALTERNATE_NAME_CODE, ADMIN_NAME, AUDIT_NAME, VALID_DATE, AUDIT_ACTION, DIRECTOR_CLASS, STAT_SEQ) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)] ---> System.Data.Odbc.OdbcException
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
at NHibernate.AdoNet.NonBatchingBatcher.AddToBatch(IExpectation expectation)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
--- End of inner exception stack trace ---
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Boolean[] notNull, Int32 j, SqlCommandInfo sql, Object obj, ISessionImplementor session)
at NHibernate.Persister.Entity.AbstractEntityPersister.Insert(Object id, Object[] fields, Object obj, ISessionImplementor session)
at NHibernate.Impl.StatelessSessionImpl.Insert(String entityName, Object entity)
at NHibernate.Impl.StatelessSessionImpl.Insert(Object entity)
at Domain.Repositories.StatelessRepository.Add[T](T model) in c:\Users\Owner\Dev\\Domain\Repositories\StatelessRepository.cs:line 112
at PatchImport.Program.InsertBeneficiaries() in c:\Users\Owner\Dev\PatchImport\Program.cs:line 232
at PatchImport.Program.Main(String[] args) in c:\Users\Owner\Dev\PatchImport\Program.cs:line 60
The inner exception has no message attached to it.
I have looked at the SQL generated by NHibernate. Using the development settings, SQL generated for the input looks like this:
NHibernate: select STRUCTURE_SEQ.nextval from dual
NHibernate: INSERT INTO STRUCTURE_ASSIGN
(CLIENT_ID, STRUCTURE, NAME_CODE, START_DATE, STAT_SEQ)
VALUES (:p0, :p1, :p2, :p3, :p4);
:p0 = 'MAST17' [Type: String (6)],
:p1 = 'BENEFICIARY' [Type: String (11)],
:p2 = 27845 [Type: Int64 (0)],
:p3 = 28/10/2008 00:00:00 [Type: DateTime (0)],
:p4 = 42830 [Type: Int32 (0)]
However, with production settings the generated SQL looks like this:
NHibernate: select STRUCTURE_SEQ.nextval from dual
NHibernate: INSERT INTO STRUCTURE_ASSIGN
(CLIENT_ID, STRUCTURE, NAME_CODE, START_DATE, STAT_SEQ)
VALUES (?, ?, ?, ?, ?);
p0 = 'SCAR03' [Type: String (6)],
p1 = 'BENEFICIARY' [Type: String (11)],
p2 = 21525 [Type: Int64 (0)],
p3 = 07/11/1977 00:00:00[Type: DateTime (0)],
p4 = 35159 [Type: Int32 (0)]
Nothing else in the code has changed - only the configuration files.
Does anyone have any idea what is going wrong here? I suspect that it is either the use of sequences to generate the ID for the table (the STAT_SEQ
column) , or whatever is causing the parameters in the second set of SQL to be ?
rather than p0
,p1
etc.