December 16, 2009 at 5:13 am
Hello ,
I m using following link to create assembly and stored proc using c#.net
http://social.msdn.microsoft.com/Forums/en/sqlnetfx/thread/53dc2eb9-f077-4043-9f76-a0460c1f9332
I have c#.net class library project which uses MATLAB dll as my external dll . I have to use matlab dll for few calculation. Matlab dll is strong name dll and properly versioned.
Code.
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.SqlServer.Server;
using MathWorks.MATLAB.NET.Arrays;
namespace Test_Wit_Strong_Name
{
public class Sp1
{
[Microsoft.SqlServer.Server.SqlProcedure]
public static void Add_Two_Numbers(int a, int b)
{
SqlPipe pipe = SqlContext.Pipe;
test_sum.majid_class test =new test_sum.majid_class();
//test_sum.majid_class test = (test_sum.majid_class)Activator.CreateInstance(typeof(test_sum.majid_class));
double[] a1 = new double[1] { a };
double[] b1 = new double[1] { b };
MWNumericArray mwnA = new MWNumericArray(a1);
MWNumericArray mwnB = new MWNumericArray(b1);
String Sum = Convert.ToString(test.majid_sum(mwnA, mwnB));
pipe.Send(Sum);
}
[Microsoft.SqlServer.Server.SqlProcedure]
public static void Square(int a)
{
SqlPipe pipe;
pipe = SqlContext.Pipe;
/* Test 1 without Matlab */
int result = a * a;
pipe.Send(result.ToString());
}
}
}
I have two functions Square, Add_Two_Numbers . when i tested only for square function, assembly and procedure created properly .because it does not have matlab instance in it. (here I need to hide Add_Two_Numbers function fron class )
But when I m trying for Add_Two_Numbers and executing following statemnt in query analyser.
CREATE ASSEMBLY assembly1 FROM 'C:\MatlabTest\Test_Wit_Strong_Name\Test_Wit_Strong_Name\bin\Debug\Test_Wit_Strong_Name.dll'
WITH PERMISSION_SET = UNSAFE --EXTERNAL_ACCESS
It throws me error like
Msg 6586, Level 16, State 1, Line 2
Assembly 'System.Drawing' could not be installed because existing policy would keep it from being used.
Can you please help me to create stored procedure from class libaray which have matlab function as external dll.
many Thanks
Majidkhan
December 17, 2009 at 7:26 pm
//test_sum.majid_class test = (test_sum.majid_class)Activator.CreateInstance(typeof(test_sum.majid_class));
The thread you posted is not related to your problem the above line of code tells SQL Server you are loading the assembly through reflection which is not supported in SQL Server. So if you can create your assembly without TypeOf then it may run. The issue here is SQL Server will not load assembly through type discovery which is what you do with TypeOf.
Kind regards,
Gift Peddie
December 17, 2009 at 10:30 pm
Thank you very much for your replay ,
The line which you have mention (//test_sum.majid_class test = (test_sum.majid_class)Activator.CreateInstance(typeof(test_sum.majid_class));) is commented in my code.
Actual I have created object by using new.( test_sum.majid_class test =new test_sum.majid_class();)
I have tested with both but still I m facing this problem.
please correct me if I m wrong with my code.
Thank you
Majid khan
December 19, 2009 at 8:35 am
Assembly 'System.Drawing' could not be installed because existing policy would keep it from being used.
Two things I did not see system.drawing in your using statements so you must have a class in your code implicitly calling it. You could write .NET code and consume it with Assembly.Load which is not allowed in SQL Server CLR.
Kind regards,
Gift Peddie
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply