Skip to content

Instantly share code, notes, and snippets.

@luiscelismx
Last active March 5, 2019 18:36
Show Gist options
  • Select an option

  • Save luiscelismx/9272646 to your computer and use it in GitHub Desktop.

Select an option

Save luiscelismx/9272646 to your computer and use it in GitHub Desktop.
Procedimiento almacenado en SQL para levantar una unidad de red y ser utilizada por SQL Server
USE [MYDB]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Luis Antonio Celis Molina
-- Create date: 17/Junio/2013
-- Description: Procedimiento creado para hacer visible la unidad de red donde llegan los archivos EDI
-- en el servidor "" a la carpeta "Incoming".
-- El procedimiento tiene que quedar como de ejecución automatica para que se levante si se reinicia el servicio de SQL
-- Modificar los valores de servidor, carpeta, nombre de usuario y contraseña
-- =============================================
CREATE PROCEDURE [dbo].[Mapear_Unidad_Red_EDI]
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Permitir que las opciones avanzadas puedan ser modificadas.
EXEC sp_configure 'show advanced options', '1';
RECONFIGURE
-- Habilitar la caracteristica de que se pueda ejecutar comandos de Windows(xp_cmdshell).
EXEC sp_configure 'xp_cmdshell', '1';
RECONFIGURE
--Verificar si la unidad de red R: esta conectada.
DECLARE @result int
EXEC @result = xp_cmdshell 'DIR U:\'
IF (@result != 0)
-- Conectar la unidad de Red donde se haran los respaldos
EXEC xp_cmdshell 'net use U: "\\servidoRed\carpeta" /user:miUsuario contraseña'
END
@lottusUteq2013
Copy link

Excelente aporte, me sirvió full.

Gracias

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment