简体   繁体   中英

Cannot install assembly on SQL Server 2008

I made some library and want to use it as CLR assembly in MSSQL. The point is that my lib have the reference to 'iAnywhere.Data.SQLAnywhere' lib which I cannot install. The error is:

Assembly 'iAnywhere.Data.SQLAnywhere' could not be installed because existing policy would keep it from being used.

I have implemented the recommendations and now my SQL looks like:

USE DB_Control
GO 

ALTER DATABASE DB_Control SET TRUSTWORTHY ON WITH ROLLBACK IMMEDIATE
GO

ALTER DATABASE DB_Control SET TRUSTWORTHY ON
GO

exec sp_configure 'show advanced options', 1;
GO

RECONFIGURE;
GO

exec sp_configure 'clr enabled', 1;
GO

RECONFIGURE;
GO

CREATE ASSEMBLY [iAnywhere.Data.SQLAnywhere]
AUTHORIZATION sa
FROM '~\Debug\iAnywhere.Data.SQLAnywhere.dll'
WITH PERMISSION_SET = UNSAFE
GO

CREATE ASSEMBLY ClrSqlMediator
AUTHORIZATION sa
FROM '~\Debug\SQLMediator.dll'
WITH PERMISSION_SET = UNSAFE
GO

Does anybody know how to fix this?


Upd: Server version is SQL Server 2008 R2 (x64). My MediatorCLR built as x64 lib, but I almost shure SQLAnywhere.dll built as x86. Can it be the reason?


Upd2: Here is Dropbox link to libs: x64 - https , x86 - https .


Upd3: I start thinking that SQLAnywhere.dll cannot be loaded at all because of x86 build option and I'm not sure that it has public static methods that is required. Surely i got to implement some other kind of reference.

Pay attention to there clauses

FROM '~\Debug\iAnywhere.Data.SQLAnywhere.dll'
FROM '~\Debug\SQLMediator.dll'

Here you should specify a valid path from SQL Server machine, after you have copied that .dll on SQL Server machine.

Alternatively , in case you don't have access to SQL Server file system in order to copy your assembly file, you can generate hex code , then register .NET assembly:

CREATE ASSEMBLY <AssemblyName.dll>
AUTHORIZATION [dbo]
FROM <0x4D5A9000030000000400000.... generated hex code here>
WITH PERMISSION_SET = SAFE
GO

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM