I'm attempting to add an assembly to a database in SQL2008 using an asymmetric key.
We're adding the assembly using a hex string (adding assemblies to servers through sql queries only)
USE [master]
GO
IF NOT EXISTS (SELECT * from sys.asymmetric_keys where name = 'ManagedAsymmetricKey')
BEGIN
CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM FILE = 'C:\Managed.dll'
CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
GRANT UNSAFE ASSEMBLY TO CLRLogin
END
GO
USE [$dbName]
GO
CREATE ASSEMBLY [Managed]
AUTHORIZATION [dbo]
FROM 0x4D5A....
WITH PERMISSION_SET = UNSAFE
GO
This will work on a local instance however over the network we receive;
The certificate, asymmetric key, or private key file does not exist or has invalid format.
I may be assuming wrongly that I should be adding the key first, should I be adding the assembly then doing something along the lines of CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [workingDB].[dbo].[Managed]
?
You can use the following steps to get it working:
grant the login unsafe assembly rights
CREATE ASSEMBLY [Managed]
AUTHORIZATION [dbo]
FROM 0x4D5A....
WITH PERMISSION_SET = SAFE
CREATE ASYMMETRIC KEY ManagedAsymmetricKey FROM ASSEMBLY [Managed]
DROP ASSEMBLY [Managed]
CREATE LOGIN CLRLogin FROM ASYMMETRIC KEY ManagedAsymmetricKey
GRANT UNSAFE ASSEMBLY TO CLRLogin
The FROM FILE =
is always from the perspective of SQL Server. You would have copy the certificate to a local drive on the database server.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With