Hello and thank you for your help. I must write non-tabular information to a file. I have tried a few methods that invoke various stored procedures. The following SQL statement tests this and I don't know how to make it work. I have evaluated and set permission for the MSSQLSERVER user on the directory. Would someone help me please?
-- Declarations DECLARE @FileSystem INT; DECLARE @FileHandle INT; DECLARE @FilePath VARCHAR(255); DECLARE @ForWriting INT; DECLARE @CreateIfNeeded INT; DECLARE @TextStream INT; DECLARE @TextToWrite VARCHAR(MAX); -- Set the file path SET @FilePath = 'C:\Users\crmcw\AppData\Local'; SET @ForWriting = 2; -- Constant for write mode SET @CreateIfNeeded = 8; -- Constant to create the file if it doesn't exist -- Create the FileSystemObject EXEC sp_OACreate 'Scripting.FileSystemObject', @FileSystem OUT; -- Open the file using the OpenTextFile method EXEC sp_OAMethod @FileSystem, 'OpenTextFile', @FileHandle OUT, @FilePath, @ForWriting, @CreateIfNeeded; -- Check if the file handle was successfully obtained IF @FileHandle <> 0 BEGIN -- File handle obtained, proceed with writing to the file SET @TextToWrite = 'This is the text to write to the file.'; -- Write the text to the file EXEC sp_OAMethod @FileHandle, 'WriteLine', NULL, @TextToWrite; -- Close the file EXEC sp_OAMethod @FileHandle, 'Close'; -- Clean up the COM objects EXEC sp_OADestroy @FileHandle; EXEC sp_OADestroy @FileSystem; PRINT 'File created and written successfully.'; END ELSE BEGIN -- File handle not obtained, there was an error PRINT 'Failed to create or open the file.'; END