Sqlserver te da la opción de poder ejecutar comandos del CMD por medio del xp_cmdshell pero por seguridad esta inactivo, si lo ejecutas sin activar te dará el siguiente error::
Habilitar el xp_cmdshell
Una vez ejecutado provemos
Listo, funcionando
Desactiva el xp_cmdshell
Si ya no deseamos tener activa el xp_cmdshell lo desactivamos de la siguiente forma:
Espero les sirva.
Executed as user: NT SERVICE\SQLSERVERAGENT. SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online. [SQLSTATE 42000] (Error 15281).
Solución
Para solventar este problema solo hay que habilitar , veamos el ejemplo
Comando
| xp_cmdshell 'dir c:\' |
Salida de Error
| xp_cmdshell 'T SERVICE\SQLSERVERAGENT. SQL Server blocked access to procedure 'sys.xp_cmdshell' of component 'xp_cmdshell' because this component is turned off as part of the security configuration for this server. A system administrator can enable the use of 'xp_cmdshell' by using sp_configure. For more information about enabling 'xp_cmdshell', search for 'xp_cmdshell' in SQL Server Books Online. [SQLSTATE 42000] (Error 15281) |
Habilitar el xp_cmdshell
| -- Activar las opciones avanzadas para activar xp_cmdshell sp_configure 'show advanced options', '1' RECONFIGURE |
| -- Activar xp_cmdshell sp_configure 'xp_cmdshell', '1' RECONFIGURE |
Una vez ejecutado provemos
| xp_cmdshell 'dir c:\' |
Desactiva el xp_cmdshell
Si ya no deseamos tener activa el xp_cmdshell lo desactivamos de la siguiente forma:
| -- Activar las opciones avanzadas para activar xp_cmdshell sp_configure 'show advanced options', '1' RECONFIGURE |
| -- Desactiva xp_cmdshell sp_configure 'xp_cmdshell', '0' RECONFIGURE |
Espero les sirva.














