--open GO sp_configure 'show advanced options', 1 RECONFIGURE GO sp_configure 'Ole Automation Procedures', 1 RECONFIGURE GO EXEC sp_configure 'Ole Automation Procedures' DECLARE @DATA VARBINARY(MAX) DECLARE @ObjectToken INT DECLARE @TIMESTAMP VARCHAR(MAX) SET @TIMESTAMP = 'd:abc.png' EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT EXEC sp_OASetProperty @ObjectToken, 'Type', 1 EXEC sp_OAMethod @ObjectToken, 'Open' EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @DATA EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, @TIMESTAMP, 2 EXEC sp_OAMethod @ObjectToken, 'Close' EXEC sp_OADestroy @ObjectToken SELECT @TIMESTAMP --close GO sp_configure 'show advanced options', 1 RECONFIGURE GO sp_configure 'Ole Automation Procedures', 0 RECONFIGURE GO EXEC sp_configure 'Ole Automation Procedures' GO sp_configure 'show advanced options', 0 RECONFIGURE