0

SQL Server and CLR Assemblies C# - 6 Steps

by sciske 28. August 2007 07:39

I had a chance to play around with this new feature in SQL 2005 the other day.  After reading a few articles here is the quick and dirty on how to implement.

A quick and dirty guide as to when is the best time to use:

http://www.developer.com/net/net/article.php/3528601

 How to add:

1) Create a Class project in Visual Studio

2) Create a new class and cut and paste the following code:

using System;
using System.Collections.Generic;
using System.Text;

namespace SampleCLR
{
    public class CLRTestClass
    {

        public static string Freak(string name)
        {
            return name.ToString() + " Is a FREAK!!!";

        }
    }
}

 

3) Compile.

4) Next

Register the assembly (in SQL 2005) by right clicking ‘Assemblies’ > ‘New Assembly’ under Programmability.

5) Run these scripts:

  SET ANSI_NULLS ON

GO

SET QUOTED_IDENTIFIER ON

GO

CREATE FUNCTION dbo.clrWhosFreak(  @name as nvarchar(200) ) RETURNS nvarchar(4000)  AS EXTERNAL NAME [SampleCLR].[SampleCLR.CLRTestClass].[Freak]  

sp_configure 'clr enabled', 1

go

reconfigure

go   

6) Then open a query window and run….  

select dbo.clrWhosFreak('Steve')

 

Tags: , , ,

Comments are closed

Powered by BlogEngine.NET 2.5.0.6
Original Design by Laptop Geek, Adapted by onesoft