Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2008 Forums
 SQL Server Administration (2008)
 got error when executing assembly

Author  Topic 

Oliver wang
Yak Posting Veteran

50 Posts

Posted - 2012-09-16 : 10:16:11
Hi everyone,

I'm trying to run a c# assembly in SQL Server. the assembly code is as below:
using System;
using System.Data.SqlTypes;
using System.Data.SqlClient;
using Microsoft.SqlServer.Server;

namespace TK433.Clr
{
public class Demo
{
static public void CustomerGetProcedure(SqlInt32 customerId)
{
//using (SqlConnection conn = new SqlConnection("context connetion=true"))
//{
SqlConnection conn = new SqlConnection();
conn.ConnectionString = "Data Source=local;Initial Catalog=AdventureWorks2008R2;Integrated Security=SSPI;";
SqlCommand cmd=conn.CreateCommand();
cmd.CommandText = @"select * from Sales.Customer where customerId=@customerId";
cmd.Parameters.AddWithValue("@customerId", customerId);
conn.Open();
SqlContext.Pipe.ExecuteAndSend(cmd);
//}
}
}
}

Here I just omit some middle processing I've done. Then I created an stored procedure as below:

create procedure sales.spCustomerGetClr @CustomerID Int
as
external name myassembly."TK433.Clr.Demo".CustomerGetProcedure;

When I execute the SP, I got an error like this: Request for the permission of type 'System.Data.SqlClient.SqlClientPermission, System.Data, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.

Does anyone have any idea on this? I'm stuck on it. Thanks for your time and effort.

regards,

Oliver
   

- Advertisement -