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 2005 Forums
 Transact-SQL (2005)
 Problem with custom SQL server Assembly

Author  Topic 

00kevin
Yak Posting Veteran

78 Posts

Posted - 2010-02-16 : 14:07:30
Recently I created an assembly in .net and hooked it up to my sql server. Everything worked fine and I had no problems until I moved it to a production machine.

At this point I've tried just about everything to get it working. I've googled this error to death and I'm still not having any luck.

I can create the assembly and I can create stored procedures from it, but when I try to execute the stored procedure I get the following error.



Msg 10314, Level 16, State 11, Line 2
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65544. 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: Could not load file or assembly 'santasclr, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The given assembly name or codebase was invalid. (Exception from HRESULT: 0x80131047)
System.IO.FileLoadException:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)


I've tried all kinds of things including the following.



alter database Santa set trustworthy on
EXEC dbo.sp_changedbowner @loginame = N'sa', @map = false

sp_configure 'clr enabled',1
go
reconfigure with override
go

alter ASSEMBLY SantasCLR
FROM 'C:\Program Files (x86)\SantasCLR\SantasCLR.dll'
WITH PERMISSION_SET = UNSAFE
go


CREATE PROCEDURE [dbo].[WorkerGetDay]
@UserName [nvarchar](max),
@Password [nvarchar](max),
@URL [nvarchar](max),
@ConnectionType [nvarchar](max),
@Day as Datetime,
@Err [nvarchar](max) output
WITH EXECUTE AS CALLER
AS
EXTERNAL NAME [SantasCLR].[Worker].GetDay



I have even given every sql account full control over the folder with the dll in it.


I've compiled 64 bit dlls and 32 bit dlls, but that doesn't work either.

any help would be appreciated.

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-16 : 15:22:17
The folder with the dll is irrelevant once it is added to SQL Server as the dll is no longer used on the file system.

Show us how you execute it when you get the error.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

00kevin
Yak Posting Veteran

78 Posts

Posted - 2010-02-16 : 16:20:57
here is how I execute it.

declare @err [nvarchar](max)
exec WorkerGetDay '7857001', '4123', 'http://www.someserver.com', 'Test', '2010-02-02', @err output

select @err

I've tried logging in as sa and that didn't work either.

The @err variable is for the error returned from the try catch block in the .net code. This variable is blank so it doesn't even execute the code inside.

I should point out that the .net code uses a COM object.


Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2010-02-16 : 20:04:16
Does it need EXTERNAL_ACCESS instead of UNSAFE?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page

00kevin
Yak Posting Veteran

78 Posts

Posted - 2010-02-16 : 22:05:16
quote:
Originally posted by tkizer

Does it need EXTERNAL_ACCESS instead of UNSAFE?




I've tried that option and it gives the same error.
Go to Top of Page

00kevin
Yak Posting Veteran

78 Posts

Posted - 2010-02-18 : 17:34:31
any ideas?
Go to Top of Page

00kevin
Yak Posting Veteran

78 Posts

Posted - 2010-02-19 : 10:11:41
ok I've figured out this issue. The problem is that you can't run a 32 bit process in a 64 bit process. Sql server executes the procedure in a 64 bit process and since the assembly is making use of a 32 bit COM object an error occurs. There is basically no way to solve this issue since you can't create a 64 bit assembly that uses a 32 bit COM object. Using the "Any CPU" option when compiling the dll doesn't work either since the assembly will automatically run as a 64 bit process and the COM object will fail to load.

The work around is to create a web service that uses the 32 bit assembly and enable 32 bit applications. Then create another 64 bit assembly that calls the web service.

It is really too bad that the error message wasn't more accurate. From what I can tell this error can occur for any number of reasons.
Go to Top of Page
   

- Advertisement -