none
output parameter in CLR stored procedure written in C++ RRS feed

  • Question

  • How can I declare output parameter in stored procedure, written in C++/CLR?
    In C# it is proc_name( out SqlInt32 value ).
    In VB.NET it is proc_name( <Out()> ByRef value As SqlInt32 ).
    And in C++ ?

    Thanks a lot for support.
    Sunday, October 15, 2006 2:40 PM

Answers

  • Hi Sergey,

    This is how you would declare an output parameter in a managed C++ stored procedure:

    [Microsoft::SqlServer::Server::SqlProcedure]

    static void OutProc([System::Runtime::InteropServices::Out] System::String^% str)

    {

    str = "out param";

    }

    And this is the T-SQL that would call the stored procedure:

    declare @outStr nvarchar (4000)
    set @outStr = null
    exec OutProc @outStr out
    select @outStr

    Hope this helps,

    Ryan Wike - MSFT

    Tuesday, October 17, 2006 11:52 PM

All replies

  • I don't know C++ so much, so this is just a thought: out params should be the same as ref parameters without the need to marshal data when the function is invoked, they are marshalled back on return only... so... have you tried a ref parameter ?
    Sunday, October 15, 2006 4:39 PM
  • 
    Did you try passing a reference?
     
    void proc_name (SqlInt32 &value)
    {
    //...
    }
     
    ... just a guess, but I think it's probably a pretty good shot :)
     

    --
    Adam Machanic
    Pro SQL Server 2005, available now
    http://www..apress.com/book/bookDisplay.html?bID=457
    --
     
     
    How can I declare output parameter in stored procedure, written in C++/CLR?
    In C# it is proc_name( out SqlInt32 value ).
    In VB.NET it is proc_name( <Out()> ByRef value As SqlInt32 ).
    And in C++ ?

    Thanks a lot for support.
    Sunday, October 15, 2006 4:45 PM
  • It is not enough to declare parameter as reference. You could see in samples that for C# and VB.NET used special terms - "out" and "<Out()>" accordingly. So all what I need - such special term for C++. Without it SQL Server, creating Assembly, cannot recognize where is output parameter in appropriate method declaration.
    Sunday, October 15, 2006 4:53 PM
  • Yes, very good shot, but not for managed C++/CLR and not for SQL Server projects in Visual Studio 2005.

    Anyway, thanks for attention to my problem.
    Sunday, October 15, 2006 5:04 PM
  • Hi Sergey,

    This is how you would declare an output parameter in a managed C++ stored procedure:

    [Microsoft::SqlServer::Server::SqlProcedure]

    static void OutProc([System::Runtime::InteropServices::Out] System::String^% str)

    {

    str = "out param";

    }

    And this is the T-SQL that would call the stored procedure:

    declare @outStr nvarchar (4000)
    set @outStr = null
    exec OutProc @outStr out
    select @outStr

    Hope this helps,

    Ryan Wike - MSFT

    Tuesday, October 17, 2006 11:52 PM
  • Hi Ryan,

    Thank You for exhaustive answer!


    Sincerely yours,

    Sergey Jmacov.
    Wednesday, October 18, 2006 8:20 AM