Calling an Oracle stored procedure using NHibernate

  1. The stored procedure must have an out sys_refcursor parameter as the first argument.
  2. Tested with NHibernate 2.1.2 and Oracle 11g.
  3. Needs Oracle.DataAccess (not System.Data.OracleClient). Tested with Oracle.DataAccess AMD64.

NHibernate config:

<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <property name="connection.driver_class">

NHibernate mapping:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="SampleProject" namespace="SampleProject">
  <sql-query name="GetEmployeesByDepartmentId">
    <return class="Employee" />
    { call GetEmployeesByDepartmentId(:p_departmentid) }

C# code:

var employees = nhibernateSession
    .SetParameter("p_departmentid", departmentId)

To execute a stored procedure that has no out parameters:

    .CreateSQLQuery("call DoSomething(:p_parameter1)")
    .SetParameter("p_parameter1", parameter1)

17 January 2012 | .NET, C# | 4 Comments

LINQPad – a worthy successor to Snippet Compiler

In 2009 I blogged about how Snippet Compiler allows us to test out C# code without having to create a project in Visual Studio just for that. Now there’s something better: LINQPad. Don’t be misled by its name; it’s not just for LINQ, it can run any C#, VB, or even SQL code. I particularly like its results view. A screenshot is worth a thousand words:

5 August 2011 | .NET, C#, Applications | No Comments

Problem with Transactions on Windows 64-bit Oracle Client

After upgrading to a 64-bit machine at the office, my Visual Studio 2010 unit tests that were making heavy use of transactions (i.e., hundreds of uncommitted database table insertions within a using (new TransactionScope()) statement) failed with the following error message:

ORA-00603: ORACLE server session terminated by fatal error
ORA-00600: internal error code, arguments: [ktcirs:hds], [0×00F7D8078], [0×006F10BF0], [0×01B8C8078], [], [], [], [], [], [], [], []
ORA-00600: internal error code, arguments: [ktcirs:hds], [0×00F7D8078], [0×006F10BF0], [0×01B8C8078], [], [], [], [], [], [], [], []
Process ID: 4084
Session ID: 125 Serial number: 369

The solution

  1. Install 64-bit Oracle Client ( but do not install Oracle Services for Microsoft Transaction Server.
  2. Install only OraMTS using 64-bit Oracle Data Access Component (

What’s the problem, BTW?

“Windows Vista and Windows Server 2008 introduce new MSDTC changes that do not interoperate with older versions of Oracle Services for MTS. Oracle Services for MTS and higher, with the exception of, support these new changes on Windows Vista Service Pack 1 and Windows Server 2008 or higher.” Source:

3 August 2011 | Uncategorized | No Comments

Robocopy in lieu of rsync

Perhaps you’re a web developer familiar with Linux and SVN. Then you’ll definitely know how to copy files from your SVN working directory to a test server whilst excluding all .svn directories:

rsync -IrW --stats --exclude=.svn /path/to/project/dir/ //testsrv/whatever

If for some reason your development environment is Windows you might be tempted to use rsync on Cygwin. That’s works fine (albeit with a very noticeable performance lag), but there is actually a native Windows alternative to rsync:

robocopy \path\to\project\dir \\testsrv\whatever /MIR /XD .svn

Robocopy has long been available on NT 4.0 via the Windows Resource Kit, and is included in Vista, Windows 7, and Windows Server 2008.

1 February 2011 | LAMP, Windows | 1 Comment

Memories of the past

The past doesn’t exist, except in our minds. There is not one past, but many pasts, each belonging to a different person.

If not for memory, there would be no such thing as the past. It is literally all in the mind.

Easy enough to comprehend, but extremely difficult to internalize.

9 January 2011 | Uncategorized | 6 Comments