2010-05-21 18 views
13

Ho una DLL CLR SQL che desidero distribuire, ma ho scoperto che è possibile incorporare il flusso di byte/varbinary_literal/varbinary_expression/assembly bits in un file di testo per aggirare il fastidio di compattare una DLL e assicurarsi che sia accessibile per il CREATE ASSEMBLY command.Assembly CLR SQL: ottieni il Bytestream?

Ma quello che devo ancora trovare è come ottenere quel valore del flusso di byte/varbinary_literal/varbinary_expression/assembly bits. Non ho trovato alcuna terminologia coerente e quello che continuo a trovare nell'uso di Load().

Aiuto?

risposta

17

È solo una rappresentazione esadecimale della DLL. Questo bit dovrebbe fare il trucco:

static string GetHexString(string assemblyPath) 
    { 
     if (!Path.IsPathRooted(assemblyPath)) 
      assemblyPath = Path.Combine(Environment.CurrentDirectory, 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(); 
    } 

si dovrebbe usare la stringa risultante in questo modo:

string hexString = GetHexString(assemblyPath); 
string sql = "CREATE ASSEMBLY [" + assemblyName + "] FROM " + hexString + 
      " WITH PERMISSION_SET = " + somePermissionSet; 
+2

Grazie - le informazioni esadecimali mi hanno portato a questo codice: http://blog.waldenl.com/2009/12/command-line-hex-representation-of-file.html –

+0

praticamente lo stesso ciclo sì :) –

4

Trovato here, il varbinary possono essere generati senza codice personalizzato per la generazione di esso, solo tramite SQL Server Management Studio (SSMS) e un'istanza locale di SQL Server.

  1. create o alter vostra assemblea nel database utilizzando il percorso locale in SQL Server locale.

    use yourBase 
    go 
    create assembly YourAssemblySqlName from N'YourLocalPath\YourAssemblyFile.dll' 
    go 
    
  2. Passare al gruppo in Esplora oggetti.

    Browsing to assembly

  3. Script sua creazione.

    Scripting the assembly

E SSMS darvi il varbinary.

+2

è inoltre possibile ottenere in questo modo: ' af.content SELECT FROM sys.assemblies un INNER JOIN sys.assembly_files AF a.assembly_id = af.assembly_id DOVE a.name = <@assemblyName>' –

Problemi correlati