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 classProcs
{
// 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 classProcs
{
// uses SqlDataReader and returns results via SqlPipe
[SqlProcedure]
public static void getAuthorsByState(SqlString state)