none
Using Oracle External Procedures with C# RRS feed

  • Question

  • Hi,

    I'm using Oracle External Procedures with C# as shown here:
    http://microsoft.apress.com/asptodayarchive/73976/writing-oracle-external-procedures-with-managed-code


    So I've created Managed C++ wrapper ot the C#'s assembly and exposed the reqired methods as C++ functions.
    The problem is that when I call the C++ functions within a PL-SQL query, the C#'s assembly that is
    referenced in the C++ dll cannot be found. I tried referencing the C++ dll into a VC++ 6.0 project and
    everything works fine: the C#'s code has been executed. After that I added the C#'s assembly to the GAC
    and then I achieved the desired effect: the C#'s code was executed from a PL-SQL Query. But after removing
    the dll from the GAC and restarting the Oracle Listener thing's went back to "normal" - C#'s assembly not found.
    The process loading and executing the dll withing a PL_SQL query is extproc.exe which is running as System.


    Finally my question:

    Is there a way to call an oracle external procedure without adding the wrapped assembly to the GAC?

    Maybe it's a matter of right oracle listener configuration or VC++ reference.
    Environment: Visual Studio 2005 Team Suite and Oracle 10g.


    Thanks!

    Monday, June 2, 2008 7:00 PM

Answers

  • Also it is not related to ADO.Net (and thus unrelated to this forum), I will try to help.

     

    The managed C++ wrapper fails to load your C# assembly b/c it cannot find the DLL in the directory the process is running in. Note that it is not enough to put the wrapper and the C# assembly in the same folder.

     

    If this is a reason (I do not know if it is), try the following steps to solve this issue:

    1. put the managed C++ wrapper and the C# assembly in the same folder

    2. in the managed wrapper, add special handler for the System.AppDomain.CurrentDomain.AssemblyResolve event.

    3. in this handler, check ResolveEventArgs.Name value - if this name is your C# assembly name, load it explicitly using Assembly.LoadFrom method by building full path of C# assembly as:

        System.IO.Path.Combine(wrapperAssemblyFolder, csharpAssemblyName)

    4. return the loaded assembly from the handler

     

    If this does not help, please post this question to .Net forum.

     

    HTH,

     Nissim

    Wednesday, June 4, 2008 11:47 PM
    Moderator

All replies

  • Also it is not related to ADO.Net (and thus unrelated to this forum), I will try to help.

     

    The managed C++ wrapper fails to load your C# assembly b/c it cannot find the DLL in the directory the process is running in. Note that it is not enough to put the wrapper and the C# assembly in the same folder.

     

    If this is a reason (I do not know if it is), try the following steps to solve this issue:

    1. put the managed C++ wrapper and the C# assembly in the same folder

    2. in the managed wrapper, add special handler for the System.AppDomain.CurrentDomain.AssemblyResolve event.

    3. in this handler, check ResolveEventArgs.Name value - if this name is your C# assembly name, load it explicitly using Assembly.LoadFrom method by building full path of C# assembly as:

        System.IO.Path.Combine(wrapperAssemblyFolder, csharpAssemblyName)

    4. return the loaded assembly from the handler

     

    If this does not help, please post this question to .Net forum.

     

    HTH,

     Nissim

    Wednesday, June 4, 2008 11:47 PM
    Moderator
  • Thank you for your reply.

    I moved the post from .NET forum because I was told to by the moderator (probably he was not aware of the Oracle External procedures and when he saw "Oracle" said "Ooooh this is ADO.NET post").

    No matter. I solved my problem. The mistake was all mine. I just had to move the C# assembly to the

    %ORACLE_HOME%bin directory. You are offering a good solution, I don't have a lot experience with reflection but it sounds good.

     

    Best wishes,

    Smilyan

    Thursday, June 19, 2008 7:05 AM