Sponsored By Aspose - File Format APIs for .NET

Aspose are the market leader of .NET APIs for file business formats – natively work with DOCX, XLSX, PPT, PDF, MSG, MPP, images formats and many more!

Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 – source code

There are some notable changes from beta1 to beta2 when creating code for SQLCLR. I talked about a few of them here.
Let’s look at some code that reflects those changes.  For some
reason my cut and paste isn’t carrying over the syntax coloring from
Beta2 IDE, so I had to do color this one by hand.

The Beta 1 way to do it

 

using System;

using System.Data;

using System.Data.Sql;

using System.Data.SqlServer;

using System.Data.SqlTypes;

 

public class Procs

{

    // uses SqlDataReader and returns results via SqlPipe

    [SqlProcedure]

    public static void getAuthorsByState(SqlString state)

    {

        SqlCommand cmd = SqlContext.GetCommand();

        cmd.CommandText = “select * from authors where state = @state”;

        cmd.Parameters.Add(“@state”, SqlDbType.VarChar);

        cmd.Parameters[0].Value = state;

        SqlDataReader rdr = cmd.ExecuteReader();

        SqlPipe pipe = SqlContext.GetPipe;

        pipe.Send(rdr);

    }

}

Now lets look at the changes needed to make it work in Beta 2

The Beta 2 way to do it

 

using System;

using System.Data;

using System.Data.SqlClient; // Added this for SqlCommand object

using Microsoft.SqlServer.Server; // This used to be System.Data.SqlServer

using System.Data.SqlTypes;

 

public class Procs

{

    // uses SqlDataReader and returns results via SqlPipe

    [SqlProcedure]

    public static void getAuthorsByState(SqlString state)

    {

        // This used to be SqlContext.GetCommand()

        SqlCommand cmd = new SqlCommand(“Context Connection=true”);

        cmd.CommandText = “select * from authors where state = @state”;

        cmd.Parameters.Add(“@state”, SqlDbType.VarChar);

        cmd.Parameters[0].Value = state;

        SqlDataReader rdr = cmd.ExecuteReader();

        // This used to be SqlContext.GetPipe();

        SqlPipe pipe = SqlContext.Pipe;

        pipe.Send(rdr);

    }

}

This entry was posted in .Net Development, Sql Development. Bookmark the permalink. Follow any comments here with the RSS feed for this post.

One Response to Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 – source code

  1. johnpapa says:

    I think its getting a bit cleaner in its revisions. Uses more standard code already known to many developers, like the way to get a SqlCommand. I am looking forward to diving more into this part of the recent betas (so much to tackle, so little time!)

Leave a Reply