简体   繁体   English

流利的Nhibernate无法在程序包主体中调用oracle存储过程

[英]Fluent Nhibernate unable to call oracle stored procedure in package body

I am in a fix. 我已经解决了。 I have been trying to call a stored procedure contained within a Package Body to execute. 我一直试图调用包主体中包含的存储过程来执行。 I have tried without success. 我尝试过没有成功。 My code setup follows below; 我的代码设置如下:

My mapping file for the stored procedure is Mappings.hbm.xml, content below; 我的存储过程映射文件是Mappings.hbm.xml,内容如下;

<?xml version="1.0" encoding="utf-8"?>
  <hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="FAMS">
    <sql-query name="GenerateSchedule">
      { call DPRCN.Generate_Schedule ( :p_asset_id) }
    </sql-query>
</hibernate-mapping>

The Fluent Nhibernate setup in the Global.asax file is below; Global.asax文件中的Fluent Nhibernate设置如下:

private void NhibernateInitiator()
    {
        string cstring = ConfigurationManager.AppSettings["Fams"];
        SessionFactory = Fluently.Configure()
             .Database(OracleClientConfiguration.Oracle10.ConnectionString(c =>
                    c.Is(cstring))
                .Driver<NHibernate.Driver.OracleClientDriver>()
                .ShowSql())
            .Mappings(m =>
                      m.FluentMappings
                          .AddFromAssemblyOf<Asset>()
                          )
            .Mappings(m=>m.HbmMappings.AddFromAssemblyOf<Asset>())
            .ExposeConfiguration(c => c.SetProperty("current_session_context_class", "web"))
            .ExposeConfiguration(ConfigureEnvers)
            .ExposeConfiguration(cfg => new SchemaUpdate(cfg).Execute(false, true))
            .BuildSessionFactory();
    }

A snippet of the Oracle package HEADER Oracle包HEADER的片段

CREATE OR REPLACE PACKAGE DPRCN AS TYPE ReferenceCursor IS REF CURSOR; 
PROCEDURE  Generate_Schedule(pCursor OUT ReferenceCursor,p_asset_id IN Asset.asset_id%TYPE, p_regenerate IN BOOLEAN DEFAULT FALSE);

BODY 身体

CREATE OR REPLACE PACKAGE BODY DPRCN AS
PROCEDURE Generate_Schedule(pCursor OUT ReferenceCursor,p_asset_id IN Asset.Asset_ID%TYPE,
p_regenerate IN BOOLEAN DEFAULT FALSE) AS


BEGIN
OPEN pCursor FOR
.
.
.
.

END Generate_Schedule;

When i call the stored procedure with the code below, 当我使用以下代码调用存储过程时,

var session = MvcApplication.SessionFactory.GetCurrentSession();
var qry = session.GetNamedQuery("DPRCN.Generate_Schedule");
                    qry.SetParameter("p_asset_id", p.assetId);
                    qry.SetParameter("p_regenerate", false);
                    qry.List();

i get an error. 我得到一个错误。 A snippet of the error encountered below; 下面遇到的错误的摘要;

NHibernate.Exceptions.GenericADOException was caught
HResult=-2146232832
Message=could not execute query
[ { call DPRCN.Generate_Schedule ( ?) } ]
Name:p_asset_id - Value:3
[SQL: { call DPRCN.Generate_Schedule ( ?) }]
Source=NHibernate
SqlString={ call DPRCN.Generate_Schedule ( ?) }
.
.
.
InnerException: System.NotImplementedException
HResult=-2147467263
Message=OracleClientDriver does not support CallableStatement syntax (stored      procedures). 
Consider using OracleDataClientDriver instead.
Source=NHibernate
StackTrace:
at NHibernate.Driver.OracleClientDriver.OnBeforePrepare(IDbCommand command)

I will be delighted if someone can enlighten me on the way forward. 如果有人能启发我前进的道路,我将感到非常高兴。 Am really stuck here. 我真的被困在这里。 Thanks. 谢谢。

Update 更新资料

I have tried the suggestion, i changed to OracleDataClientDriver and imported Oracle.DataAccess.dll but that project did not compile. 我尝试了该建议,将其更改为OracleDataClientDriver并导入了Oracle.DataAccess.dll,但该项目未编译。 Running on windows 7 x64. 在Windows 7 x64上运行。 Error encountered was; 遇到的错误是;

[BadImageFormatException: Could not load file or assembly 'Oracle.DataAccess' or one of its dependencies. An attempt was made to load a program with an incorrect format.]

Update2 @mmjak helped resolve initial error but then got an again. Update2 @mmjak帮助解决了最初的错误,但随后又得到了。 NHProfiler read exception trace as; NHProfiler将异常跟踪读取为;

{ call DPRCN.Generate_Schedule ( 1 /* :p0 */, 0 /* :p1 */) }    Oracle.DataAccess.Client.OracleException ORA-06550: line 1, column 7:
PLS-00306: wrong number or types of arguments in call to 'GENERATE_SCHEDULE'
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored    at Oracle.DataAccess.Client.OracleException.HandleErrorHelper(Int32 errCode, OracleConnection conn, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src, String procedure)
   at Oracle.DataAccess.Client.OracleException.HandleError(Int32 errCode, OracleConnection conn, String procedure, IntPtr opsErrCtx, OpoSqlValCtx* pOpoSqlValCtx, Object src)
   at Oracle.DataAccess.Client.OracleCommand.ExecuteNonQuery()
   at NHibernate.AdoNet.AbstractBatcher.ExecuteNonQuery(IDbCommand cmd)
   at NHibernate.Engine.Query.NativeSQLQueryPlan.PerformExecuteUpdate(QueryParameters queryParameters, ISessionImplementor session)

it is looks like confilicts between x86 and x64, one dirty but working solution when you're using odp.net: 它看起来像x86和x64之间的冲突,这是使用odp.net时一个肮脏但有效的解决方案:

  1. delete reference from project 从项目中删除参考
  2. copy oci.dll, oracle.data.access.dll, oraocie11.dll, oraops11w.dll from your oracle installation folder to bin of your application 从您的oracle安装文件夹中将oci.dll,oracle.data.access.dll,oraocie11.dll,oraops11w.dll复制到应用程序的bin中
  3. add reference > browse - select previously copied oracle.dataaccess.dll 添加参考>浏览-选择先前复制的oracle.dataaccess.dll
  4. select copy local - true and specific version = true 选择本地副本-true和特定版本= true
  5. enable 32bit apps on you app pool 在您的应用程序池中启用32位应用程序
  6. then you must change your connectionString to format 那么您必须将connectionString更改为format

    Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=[address])(PORT=1521))(CONNECT_DATA=(SERVICE_NAME=[tns]))); 数据源=(DESCRIPTION =(地址=(协议= TCP)(主机= [地址])(端口= 1521))(连接_数据=(服务名称= [tns])))); User Id=[username]; 用户ID = [用户名]; Password=[password]; 密码= [密码];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM