How to call a C # function in a stored procedure

SQL Server 2005 supports the CLR, so that means we can use the CLR in the backend, so how to do this, I have some function in C # that does some complicated manipulations with the date and time variable, now I want to use these functions in SP. First of all, IT IS POSSIBLE TO DO IT.

+5
source share
2 answers

Yes, you can use .NET in a SQL Server 2005 database. Keep in mind that the .NET version supported by SQL Server 2005 is 2.0.

Here is a link to introduce to creating a CLR stored procedure using Visual Studio

+3

TSQL

USE [XXX] GO SET ANSI_NULLS OFF GO SET QUOTED_IDENTIFIER OFF GO CREATE PROCEDURE [dbo].[Testing_XXX]
@broadcastId [int],
@XXXTemplateHtml [nvarchar](max),
@XXXTemplateText [nvarchar](max),
@XXXTemplateSubject [nvarchar](max),
@XXXTemplateEmailHeaders [nvarchar](max),
@XXXTemplateHeader [nvarchar](max),
@XXXTemplateFooter [nvarchar](max),
@masterTemplate [nvarchar](max),
@parseOptions [nvarchar](4000),
@xsltTemplate [nvarchar](max) OUTPUT WITH EXECUTE AS CALLER AS EXTERNAL NAME  SolutionXXX.ProjectXXX].[StoredProcedures].[XXX_Parser_Parse] GO

EXTERNAL NAME [SolutionXXX.ProjectXXX].[StoredProcedures].[XXX_Parser_Parse]

#,

 [SqlProcedure]
public static void XXX_Parser_Parse(
    SqlInt32 broadcastId,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateHtml,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateText,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateSubject,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateEmailHeaders,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateHeader,
    [SqlFacet(MaxSize = -1)] 
    SqlString XXXTemplateFooter,
    [SqlFacet(MaxSize = -1)] 
    SqlString masterTemplate,
    SqlString parseOptions,
    [SqlFacet(MaxSize = -1)] 
    out SqlString xsltTemplate)
{
//blah blah blh
}
-1

All Articles