Saturday, February 25, 2012

assembly for stored procedure

I was playing around with the CLR in writing assemblies for the sql server 2005 stored procedure. I guess the example i found was for the beta version

This line is from the beta but no longer works. Any ideas what will fix this. There is no longer GetCommand property.

SqlCommand cmd =SqlContext.GetCommand();

Example

publicpartialclassStoredProcedures{[Microsoft.SqlServer.Server.SqlProcedure] publicstaticvoid StoredProcedure1()

{

// Put your code here

SqlCommand cmd =SqlContext.GetCommand();

cmd.CommandText="select firstname + ' ' + lastname + as [name] from person.contact";

SqlDataReader rdr = cmd.ExecuteReader();

SqlPipe sp =SqlContext.GetPipe();

sp.Send(rdr);

}};

Hi,

yes that has changed quite a bit till SQL 2005's RTM. Something like

using(SqlConnection connection = new SqlConnection("context connection=true"))
{

connection.Open();
SqlCommand cmd=new SqlCommand("select firstname + ' ' + lastname + as [name] from person.contact",connection);

SqlContext.Pipe.ExecuteAndSend(cmd);

}

For more information:http://msdn2.microsoft.com/en-us/library/ms190790.aspx

No comments:

Post a Comment