--SQL SERVER – Enable xp_cmdshell using sp_configure --The xp_cmdshell option is a server configuration option that enables system administrators to control whether the xp_cmdshell extended stored procedure can be executed on a system. ---- To allow advanced options to be changed. EXEC sp_configure 'show advanced options', 1 GO --To update the currently configured value for advanced options. RECONFIGURE GO -- To enable the feature. EXEC sp_configure 'xp_cmdshell', 1 GO -- To update the currently configured value for this feature. RECONFIGURE GOThen this is an example of where I have a script that is writing a script ( to .sql file )
DECLARE @source VARCHAR(200) DECLARE @result VARCHAR(200) DECLARE @cmd VARCHAR(200) SET NOCOUNT ON SET @source = '"C:\Users\HARRY\Documents\SQL Server Management Studio\PDS\Create Script to drop all rowguidcols.sql"' SET @result = '"C:\Users\HARRY\Documents\SQL Server Management Studio\PDS\Drop all Membership rowguidcols.sql"' SET @cmd = 'SqlCmd -E -S (local) -i '+@source + ' -o ' +@result EXEC master..xp_cmdshell @cmd;Biggest gotcha is making sure you have permissions enabled on the folder where you are writing the file.