Hello
I wanted to develop my own dll, which would be installed in sql srv 2012.
The goal of the library is to alow for communication between sql server and th "R" (is a free software environment for statistical computing: http://www.r-project.org/)
For that purpose I used R.Net (http://rdotnet.codeplex.com/), which provides R.Net.dll (which I install as a reference in my c# project)
The project (output.dll) is compiled for 'Any CPU' and for ".Net 4 Client Profile" and it works - I am able to load it by console application and successfully run calculations using "R"
Now I would like to install this assembly inside sql server and create stored procedures out of methods (decorated with [SqlProcedure()]) to do the same calculations triggered by SQL (instead of Console Application) and here is where I am getting problems:
1/ Installing Assembly (Sql2R) in db:
create assembly "Sql2R" from 'filepath\output.dll'
with permission_set=unsafe;
-> OK (Db is set as Thrustworthy )
2/ create procedure, which consumes method deliovered inside output.dll -> OK
example:
create procedure clr_getTimeRange
@left decimal =0.1
,@right decimal =0.9
,@outputVal decimal out
as
external name
[Sql2R].[Sql2R.CLR].[getTimeRange]
go
3/ Executing Stored procedure:
USE [myDB]
GO
DECLARE @return_value int,
@outputVal decimal(18, 0)
EXEC @return_value = [dbo].[clr_getTimeRange]
@left = 0.1,
@right = 0.9
,@outputVal = @outputVal OUTPUT
SELECT @outputVal as N'@outputVal'
SELECT 'Return Value' = @return_value
GO
gives me an ERROR:
Msg 10314, Level 16, State 11, Line 5
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65552. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation
to see how to solve the assembly trust issues. For more information about this error:
System.IO.FileLoadException: Nie można załadować pliku lub zestawu 'output, Version=1.0.0.0, Culture=neutral, PublicKeyToken=aceaeaec68776e20' lub jednej z jego zależności. Podana nazwa zestawu lub ścieżka bazowa kodu jest niepoprawna. (Wyjątek od HRESULT:
0x80131047 -> Which means it cannot load file or assembly or one of it's dependency. Given path or name is incorrect)
System.IO.FileLoadException:
w System.Reflection.RuntimeAssembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, RuntimeAssembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection, Boolean suppressSecurityChecks)
w System.Reflection.RuntimeAssembly.InternalLoadAssemblyName(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection, Boolean suppressSecurityChecks)
w System.Reflection.RuntimeAssembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
w System.Reflection.Assembly.Load(String assemblyString)
I tried to do this in 2 ways:
a/ registed assembly in sql server. But at some stage, when running the procedure, I got error that the assembly tries to load [RDotNet.dll], which is not acceptable (It says I am not allowed to access remote dll neither used as a reference while building
or by dynamical loading (Invoke is also not allowed)).
To work this around, I merged my custom dll and RDotNet dll (with ilmerge) to one dll: output.dll, which I added as a reference
Additionally I signed the dll with keyPair.snk, so that there is no error about missig strong name
However, this still gets me nowhere
The question is what I am doing wrong and what should be the correct way of implementing a dll, which consumes external services
Thank you very much for spending time on reading this and for any hints. I guess I am blocked now and I can nly rely on your help
Kind Regards
Clogg