2

I know how to load a CLR DLL in SQL Server and access to its static methods which does not incorporate output parameters in their method signatures but what I cannot realize is how I can use methods which have output parameters.

For example it is strightforward to access Math.dll 's factorial method in SQL server like this:

CREATE ASSEMBLY MathAsm FROM 'C:\Programming\c#\SQLCLRIntegrationExample\assemblies\Math.dll'
 WITH PERMISSION_SET = EXTERNAL_ACCESS;
Go
CREATE FUNCTION Factorial(@x FLOAT)
 RETURNS FLOAT
 EXTERNAL NAME MathAsm.Math.Factorial;
Go

But what if method's signature would be like:

public static int GetInfo(int[] inputParams, out int[] outputParams)
Justin Dearing
2,7276 gold badges36 silver badges52 bronze badges
asked Jan 29, 2014 at 11:22
0

1 Answer 1

2

What have you tried and what error are you getting?

The following works for me on SQL Server 2008 R2.

C#:

namespace CLRTest
{
 public static class ParamsTest
 {
 [SqlProcedure]
 public static void Test(out int p)
 {
 p = 5;
 }
 }
}

SQL:

CREATE PROCEDURE dbo.Test(@p int OUTPUT)
 AS EXTERNAL NAME [CLRTest].[CLRTest.ParamsTest].[Test];
GO
DECLARE @x int;
EXEC dbo.Test @p = @x OUTPUT;
SELECT @x;

Returns 5 as expected.


Now, if you're trying to return an array in an output parameter, I don't think that's supported, save for the exceptions noted here. If that's what you're looking to do, use a table-valued function or stored procedure to return a result set. Note also that table-valued (input) parameters are not supported as mentioned here, assuming you're using SQL Server 2008 or higher.

answered Jan 29, 2014 at 15:04
1
  • Thanks Jon, your answer was really helpful because I did not have a clue Commented Jan 29, 2014 at 17:07

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.