Showing posts with label succesfully. Show all posts
Showing posts with label succesfully. Show all posts

Friday, March 23, 2012

Problems Creating TVF function

I had succesfully created a CLR function which was fully operational on the development server. Today the powers that be decided to do a full restore from the Production server because the wanted the most recent data on the server. Since our code has not been deployed to production I went through the exercise of redeploying everything to the server and all goes well until I try to create the function:

Code Snippet

CREATE FUNCTION f_GetGroupMembership(@.providerKey nvarchar(200), @.connection nvarchar(1000))

RETURNS TABLE (groupID uniqueidentifier, groupName nvarchar(100), groupType nvarchar(25))

AS

EXTERNAL NAME NavigatorSecurity.groups.GetGroupsForUser

This returns an error:

Msg 10305, Level 16, State 1, Procedure f_GetGroupMembership, Line 1

The Init method for a CLR table-valued function must be annotated with SqlFunctionAttribute.

Now remember this CLR was working correctly previous to the restore from backup. But just in case I got a case of dumb*** I checked my clr code anyhow here it is:

Code Snippet

using System;

using System.Data;

using System.Data.Sql;

using System.Data.SqlTypes;

using System.Data.SqlClient;

using Microsoft.SqlServer.Server;

using System.DirectoryServices;

using System.Collections;

public class GroupMembership

{

[SqlFunctionAttribute(FillRowMethodName = "FillGroupRow")]

public static IEnumerable GetGroupsForUser(String ProviderKey, String Connection)

{

return groups.GetGroupsForUser(ProviderKey, Connection);

}

public static void FillGroupRow(Object obj, out SqlGuid guid, out SqlString name, out SqlString type)

{

//cast the enumerator passed in

group grp = (group)obj;

//create output parameters

guid = new SqlGuid(grp.guid);

name = new SqlString(grp.Name);

type = new SqlString(grp.applicationData);

}

}

Can anyone tell me why this is happening? How can I overcome this problem?

Help will be highly appreciated.

Help Please! there is no reference to this error anywhere|||
In your CREATE FUNCTION statement, you are referencing the wrong class, groups.GetGroupsForUser instead of GroupMembership.GetGroupsForUser.|||

Steven,

Thank you I figured out I did not reply here because I did not want to look like the dumba** that I am. Thanks Anyway. I'll try to review my code a third time before I make a fool of myself in public.

Regards,

MB