33

Asumir la DLL de conjunto:SQL Server: No se pudo encontrar el tipo en el montaje

using Microsoft.SqlServer.Server; 
using System.Data.SqlClient; 
using System.Data.SqlTypes; 
using System; 
using System.Text; 

namespace CLRFunctions 
{ 
    public class T 
    { 
     [SqlFunction(DataAccess = DataAccessKind.Read)] 
     public static String NormalizeString(String s, String normalizationForm) 
     { 
      NormalizationForm form = NormalizationForm.FormC; 

      if (String.Equals(f, "FormD", StringComparison.OrdinalIgnoreCase)) 
       form = NormalizationForm.FormD; 

      return = s.Normalize(form); 
     } 
    } 
} 

Nota: Haz objetivo a la asamblea para .NET 3.5 como SQL Server no admite .NET 4.0

copiar el conjunto en un lugar, y "crear" el conjunto funciona bien:

CREATE ASSEMBLY CLRFunctions FROM 'c:\Program Files\My App\CLRFunctions.dll'; 

Nota: y luego habilitar CLR funciones, de lo contrario son brokenbydefault:

sp_configure 'show advanced options', 1; 
GO 
RECONFIGURE; 
GO 
sp_configure 'clr enabled', 1; 
GO 
RECONFIGURE; 
GO 

Creado falla la función definida por el usuario:

CREATE FUNCTION NormalizeString(@s nvarchar(max), @normalizationForm varchar(50)) 
RETURNS nvarchar(max) 
AS EXTERNAL NAME CLRFunctions.T.NormalizeString 

falla con el error:

Msg 6505, Level 16, State 2, Procedure NormalizeString, Line 1 
Could not find Type 'T' in assembly 'CLRFunctions'. 

Por qué puede SQL Server no encuentra el tipo T en el ensamblaje CLRFunctions?

enter image description here

Nota: ¿Por qué T? Cause Microsoft did.

Respuesta

73

Trate

CREATE FUNCTION NormalizeString(@s nvarchar(max), 
           @normalizationForm nvarchar(50)) 
RETURNS nvarchar(max) 
AS EXTERNAL NAME CLRFunctions.[CLRFunctions.T].NormalizeString 
+3

Gran respuesta - esto fue lo que me hizo gritar obscenidades a SSMS. –

+3

en vs 2010, la plantilla predeterminada no coloca el espacio de nombres de forma predeterminada y, por lo tanto, mi nombre de clase totalmente calificado era incorrecto. la notación es: RegisteredAssemblyName. [FullyQualifiedClassName] .FunctionName –

+0

Gracias su respuesta me ayudó. –

Cuestiones relacionadas