SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On



problem with dll in clr project Expand / Collapse
Author
Message
Posted Thursday, November 12, 2009 1:44 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Thursday, December 10, 2009 3:44 PM
Points: 1, Visits: 13
I have problem with clr project.


for example:
i have external MyDLL.dll with function int add (int i, int j)
in CLR project I have MyCLR.dll with function int clr_add (int i, int j)

Problem:Can i use in clr_add external dll (MyDLL.dll)?


in MyCLR.dll I have:
...
...
[Microsoft::SqlServer::Server::SqlProcedure]
static int clr_add(int i, int j)
{
typedef int (*CALLBACK LPFNDLLFUNC1)(int,int);
HINSTANCE hDLL = NULL; // Handle to DLL
LPFNDLLFUNC1 lpfnDllFunc1; // Function pointer

hDLL = LoadLibrary(L"MyDLL.dll");

lpfnDllFunc1 = (LPFNDLLFUNC1)GetProcAddress(hDLL,"add");
int i = lpfnDllFunc1(4,6);
return i;
}
--------------------------------------------------------------------

in MS SQL :
CREATE ASSEMBLY assembly_add
FROM 'c:\_clr\MyCLR.dll'
WITH PERMISSION_SET = UNSAFE
go

CREATE PROCEDURE MyStoredProc @i int, @j int
AS EXTERNAL NAME assembly_add.[add].clr_add


declare @w int
exec @w = MyStoredProc 6,2

print @w

Error:
Msg 6522, Level 16, State 1, Procedure MyStoredProc, Line 0
A .NET Framework error occurred during execution of user-defined routine or aggregate "MyStoredProc": .

in my CLR project Common Language Runtime Support = /clr: pure,

my question: how can i in CLR SQL project use external .dll??
Post #817658
Posted Friday, November 13, 2009 4:30 AM


Mr or Mrs. 500

Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500Mr or Mrs. 500

Group: General Forum Members
Last Login: Yesterday @ 7:54 AM
Points: 546, Visits: 1,650
Not sure what you are trying to do, but to use the external dll, cant you just add it as 'reference' and then use it?

---------------------------------------------------------------------------------
Post #818376
Posted Friday, November 13, 2009 11:35 AM


SSChampion

SSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampionSSChampion

Group: General Forum Members
Last Login: Today @ 9:01 PM
Points: 20,164, Visits: 13,702
A better question... what does the CLR actually do and why do you think you need a CLR to do it?

--Jeff Moden
"RBAR is pronounced "ree-bar" and is a "Modenism" for "Row-By-Agonizing-Row".

"Data isn't the only thing that's supposed to have Integrity."

First step towards the paradigm shift of writing Set Based code:
Stop thinking about what you want to do to a row... think, instead, of what you want to do to a column."

For better, quicker answers on T-SQL questions, click on the following...
http://www.sqlservercentral.com/articles/Best+Practices/61537/

For better answers on performance questions, click on the following...
http://www.sqlservercentral.com/articles/SQLServerCentral/66909/
Post #818765
Posted Friday, November 13, 2009 12:04 PM


SSCrazy

SSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazySSCrazy

Group: General Forum Members
Last Login: Yesterday @ 3:16 PM
Points: 2,406, Visits: 1,869
Actually in SQL CLR programming you are limited in what you can add as a reference, you have to add the assembly to SQL Server FIRST then you can reference it. I don't think the method you are looking at is allowed even in an UNSAFE SQLCLR module. Also, Jeff Moden had a good question, why are you doing this in CLR?

CEWII


--------------------------------
Having trouble figuring out what jobs are running in SQL Server at the same time.
Try Sql Job History Visualization
It lets you view your SQL Job history on an Outlook style calendar..
Post #818787
« Prev Topic | Next Topic »


Permissions Expand / Collapse