sooprise
sooprise

Reputation: 23187

Deploying .dll on remote sql server?

I'm trying to create an assembly but my remote sql server cannot access my .dll file.

create assembly BarcodeSql 
from 'X:\test.dll' 
WITH PERMISSION_SET = SAFE

I don't know how to put test.dll on my sql server, but I know I can send a serialized dll instead of the path to the dll. How can I serialize the dll? I can't seem to figure it out.

Upvotes: 2

Views: 2542

Answers (2)

vcsjones
vcsjones

Reputation: 141668

I'm trying to create an assembly but my remote sql server cannot access my .dll file.

That's because it is looking for X:\ on the server where the SQL instance is running, not from where the SQL is being run from.

How can I serialize the dll?

You can specify a network path in CREATE ASSEMBLY:

create assembly BarcodeSql 
from '\\yourmachine\sharetox\test.dll' 
WITH PERMISSION_SET = SAFE

Or, you really could serialize it. Using PowerShell:

"0x" + [System.BitConverter]::ToString([System.IO.File]::ReadAllBytes("X:\text.dll")).Replace("-", "")

Which will print out some large hex value. You can then use a VARBINARY literal when creating the assembly:

create assembly BarcodeSql 
from 0x23456789
WITH PERMISSION_SET = SAFE

Where 0x123456789 is the output of the powershell script.

Upvotes: 7

Klark
Klark

Reputation: 8280

It is just simple binary representation. You can use any HEX editor, or something like this:

public string GetAssemblyBits(string assemblyPath)
{
      StringBuilder builder = new StringBuilder();
      builder.Append("0x");

      using (FileStream stream = new FileStream(assemblyPath,
            FileMode.Open, FileAccess.Read, FileShare.Read))
      {
            int currentByte = stream.ReadByte();
            while (currentByte > -1)
            {
                  builder.Append(currentByte.ToString("X2",
CultureInfo.InvariantCulture));
                  currentByte = stream.ReadByte();
            }
      }

      return builder.ToString();
}

Also, you can load assembly from network path.

CREATE ASSEMBLY assembly_name
[ AUTHORIZATION owner_name ]
FROM { <client_assembly_specifier> | <assembly_bits> [ ,...n ] }
[ WITH PERMISSION_SET = { SAFE | EXTERNAL_ACCESS | UNSAFE } ]
[ ; ]
<client_assembly_specifier> :: =
        '[\\computer_name\]share_name\[path\]manifest_file_name'
  | '[local_path\]manifest_file_name'

<assembly_bits> :: =
{ varbinary_literal | varbinary_expression }

Upvotes: 1

Related Questions