The Artima Developer Community
Sponsored Link

.NET Buzz Forum
Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 - source code

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
Raymond Lewallen

Posts: 312
Nickname: rlewallen
Registered: Apr, 2005

Raymond Lewallen is a .Net developer and Sql Server DBA
Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 - source code Posted: May 1, 2005 9:09 AM
Reply to this message Reply

This post originated from an RSS feed registered with .NET Buzz by Raymond Lewallen.
Original Post: Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 - source code
Feed Title: Raymond Lewallen
Feed URL: /error.htm?aspxerrorpath=/blogs/raymond.lewallen/rss.aspx
Feed Description: Patterns and Practices, OOP, .Net and Sql
Latest .NET Buzz Posts
Latest .NET Buzz Posts by Raymond Lewallen
Latest Posts From Raymond Lewallen

Advertisement

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);

    }

}

Read: Changes for an SQLCLR stored procedure written in Visual Studio 2005 Beta 2 - source code

Topic: Looking to Master Rich Client apps? Previous Topic   Next Topic Topic: A few changes from Beta 1 to Beta 2 when writing code for SQLCLR

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use