Ensambladores

24/03/2008 - 13:00 por bogal | Informe spam
Hola



Estoy empezando a crear ensambladores



Mi función es



Imports Microsoft.SqlServer.Server

Imports System.Data.SqlClient

Imports System.IO

Public Class clr

Inherits System.Web.UI.Page

<SqlFunction()> Public Function texto_descarga(ByVal numero As Byte, ByVal
c0 As Integer, ByVal nversion As Byte) As String

Dim strfichero As String, strruta As String, strfichero_principal As String
= Nothing

strruta = "Aplicaciones/"

strfichero = "aplicacion"

strfichero &= c0 & IIf(nversion > 0, "(" & nversion & ")", "")

strruta = Server.MapPath(strruta)

For Each foundFile As String In My.Computer.FileSystem.GetFiles(strruta,
FileIO.SearchOption.SearchTopLevelOnly, strfichero & ".*")

strfichero_principal = foundFile.Substring(InStrRev(foundFile, "\"))

Exit For

Next

If strfichero_principal Is Nothing Then strfichero_principal = "Falta " &
strfichero

Return strfichero_principal

End Function



End Class





Compilo y obtengo la dll con vbc



Luego me creo el ensamblador así



CREATE ASSEMBLY clr

'FROM 'C:\clr.dll' WITH PERMISSION_SET = safe



Pero me sale un error



Error de ejecución SQL.



Instrucción SQL ejecutada: CREATE ASSEMBLY clr FROM 'C:\clr.dll' WITH
PERMISSION_SET = safe

Origen del error: .Net SqlClient Data Provider

Mensaje de error: Error de CREATE ASSEMBLY para el ensamblado 'clr' debido a
un error de comprobación del ensamblado 'System.Drawing'. Compruebe si los
ensamblados a los que se hace referencia están actualizados y son de
confianza (para external_access o unsafe) para ejecutarse en la base de
datos. Después de este mensaje aparecen los mensajes de error de comprobación
de CLR, si los hay


[ :
System.Drawing.BufferedGraphicsContext::bFillColorTable][mdToken=0x6000243][desplazamiento
0x00000053][se encontró address of Byte] Se esperaba un tipo numérico en la
pila.


[ :
System.Drawing.BufferedGraphicsContext::bFillColorTable][mdToken=0x6000243][desplazamiento
0x00000043][se encontró Native Int][se esperaba address of Byte] Tipo no
esperado en la pila.


[ :
System.Drawing.BufferedGraphicsContext::bFillColorTable][mdToken=0x6000243][desplazamiento
0x00000027][se encontró Native Int][se esperaba address of Byte] Tipo no
esperado en la pila.


[ : System.Drawing.Icon::GetShort][mdToken=0x600045f][desplazamiento
0x00000002] Los punte...






No sé qué puede fallar. ¿Tengo que actualizar las dll a las que llaman los 3
imports? ¿Dónde obtengo las actualizaciones?




Por lo que parece, el system.drawing es llamado por System.Web.UI.Page



Pero si no pongo el inherits, no me reconoce el server.mappath, y ese es mi
problema, el usar el server.mappath. Requiere el System.Web.UI.Page



¿Me podeis guiar, por favor?



Muchas gracias de antemano

Preguntas similare

Leer las respuestas

#6 martin
27/03/2008 - 13:01 | Informe spam
Hola de nuevo

He intentado probar la función clr del ensamblado

Me da un error

Error de .NET Framework durante la ejecución de la rutina o agregado
definido por el usuario 'texto_descarga':
System.Security.HostProtectionException: Attempted to perform an operation
that was forbidden by the CLR host.

The protected resources (only available with full trust) were: All
The demanded resources were: ExternalProcessMgmt

System.Security.HostProtectionException:
at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission
permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle
rmh, Object assemblyOrString, SecurityAction action, Boolean throwException)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack
cs, PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at seguimientos.texto_descarga(SqlByte numero, SqlInt32 c0, SqlByte
nversion)


Tal vez tenga que ver con la cadena de conexión. La tengo así


<add name="conexion"
connectionString="SERVER=(local);trusted_connection=true;UID=;DataBase=nuevo;PWD="/>

Gracias por la ayuda. Busco en google, pero me es urgente y algo complicado
de entender

Muchas gracias por la paciencia y ayuda
Respuesta Responder a este mensaje
#7 martin
27/03/2008 - 14:30 | Informe spam
Hola a todos

Todo solucionado.

Por si puede resultar útil. Hay métodos y tipos que no están permitidos en
los sqlclr, udfclr...

En mi caso, al usar recursos externos, no está permitido el uso de
filesystem y sí el uso de file (system.io)

Es lo que se llama el CAS

Gracias, y un saludo
Respuesta Responder a este mensaje
#8 Jesús López
27/03/2008 - 14:33 | Informe spam
Eso no tiene que ver con la cadena de conexión. Cuando un ensamblado tiene
permiso de EXTERNAL ACCESS no significa que lo pueda hacer todo. SQL Server
impone una serie de restriccíones a las cosas que se pueden hacer para
protegerse de malas prácticas de programación y poder asegurar la
estabilidad del sistema. Cuando SQL Server detecta que el ensamblado quiere
hacer ciertas cosas prohibidas para permiso EXTERNAL ACCESS, lanza la
exceptión HostProtectionException.

Necesito ver el código de la función para ver lo que hace y que a SQL Server
no le gusta.


¿Seguro que creaste el ensamblado con EXTERNAL ACCESS?

Saludos:

Jesús López
www.soldiq.com


"martin" escribió en el mensaje
news:
Hola de nuevo

He intentado probar la función clr del ensamblado

Me da un error

Error de .NET Framework durante la ejecución de la rutina o agregado
definido por el usuario 'texto_descarga':
System.Security.HostProtectionException: Attempted to perform an operation
that was forbidden by the CLR host.

The protected resources (only available with full trust) were: All
The demanded resources were: ExternalProcessMgmt

System.Security.HostProtectionException:
at
System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Assembly
asm,
PermissionSet granted, PermissionSet refused, RuntimeMethodHandle rmh,
SecurityAction action, Object demand, IPermission permThatFailed)
at System.Security.CodeAccessSecurityEngine.ThrowSecurityException(Object
assemblyOrString, PermissionSet granted, PermissionSet refused,
RuntimeMethodHandle rmh, SecurityAction action, Object demand, IPermission
permThatFailed)
at System.Security.CodeAccessSecurityEngine.CheckSetHelper(PermissionSet
grants, PermissionSet refused, PermissionSet demands, RuntimeMethodHandle
rmh, Object assemblyOrString, SecurityAction action, Boolean
throwException)
at
System.Security.CodeAccessSecurityEngine.CheckSetHelper(CompressedStack
cs, PermissionSet grants, PermissionSet refused, PermissionSet demands,
RuntimeMethodHandle rmh, Assembly asm, SecurityAction action)
at seguimientos.texto_descarga(SqlByte numero, SqlInt32 c0, SqlByte
nversion)


Tal vez tenga que ver con la cadena de conexión. La tengo así


<add name="conexion"
connectionString="SERVER=(local);trusted_connection=true;UID=;DataBase=nuevo;PWD="/>

Gracias por la ayuda. Busco en google, pero me es urgente y algo
complicado
de entender

Muchas gracias por la paciencia y ayuda

email Siga el debate Respuesta Responder a este mensaje
Ads by Google
Help Hacer una pregunta AnteriorRespuesta Tengo una respuesta
Search Busqueda sugerida