Saturday, February 25, 2012

deploy to another server

I do not have access to VS, but I hear it can do this... how can I do it without VS?

I am using CREATE ASSEMBLY to load dll form my server to SQLServer on my server (Same machine). How can I load the dll to another server? Do I have to write it on a directory on that server first? I tried to run the command from my pc connected to the other server, and I get a "cannot find file" error.

The FROM clause in CREATE ASSEMBLY can either take a path to the dll (which is what you are doing), but it can also instead of the path take the binary representation of the dll.

So in your case, you can either use a path which the remote server accesses and has permissions to - or you can take the binary representation of the assembly instead.

Niels

|||Thanks. How do I do that binary representation? All the documentation I see is about the path to the dll. I'm new to .net development so I don't know where to go for help.|||

The syntax is

CREATE ASSEMBLY <asm_name> FROM 0x...

where 0x... is the hex binary representation.

The simplest way to get this is the use Management Studio. Choose the assembly in the object explorer, and click Script Assembly As -> Create To > New Query Editor Window. This will output the right syntax for you.

An alternative is code like below to convert the assembly to binary.

using System.IO;

using System;

using System.Text;

public class FileToHexBinary

{

public static void Main(String[] args)

{

FileStream fs = new FileStream(args[0], FileMode.Open);

int size = (int)fs.Length;

byte[] bytes = new byte [size];

fs.Read (bytes, 0, size);

fs.Close ();

StringBuilder builder = new StringBuilder(size * 2);

foreach( byte b in bytes)

{

builder.Append(b.ToString("x2"));

}

Console.WriteLine("0x" + builder.ToString());

}

}


|||Why b.ToString("x2")? What does the x2 mean? Whats the difference between "x" and "x2"?

No comments:

Post a Comment