FSO и TSQL
От: via  
Дата: 29.08.05 09:16
Оценка:
Добрый день.
Хочу из хранимой процедуры производить запись в файл.
Для этого создал скрипт:
DECLARE @FileName varchar(255), @Text1 varchar(255)
DECLARE @FS int, @OLEResult int, @FileID int, @hr int,@r int
DECLARE @source varchar(30), @desc varchar (200)
SELECT @FileName='D:\temp.txt'
EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject'

-- Open a file
-- object.OpenTextFile(filename[, iomode[, create[, format]]])
/*
IOMODE:
ForReading 1 Open a file for reading only. You can't write to this file.
ForWriting 2 Open a file for writing only. You can't read from this file.
ForAppending 8 Open a file and write to the end of the file.
CREATE: TRUE | FALSE (0,1)
FORMAT:
TristateUseDefault -2 Opens the file using the system default.
TristateTrue -1 Opens the file as Unicode.
TristateFalse 0 Opens the file as ASCII.
*/
--execute @OLEResult = sp_OAMethod @FS,'OpenTextFile',@FileID OUT, @FileName, 1, 0, 0
execute @OLEResult = sp_OAMethod @FS,'OpenTextFile',@FileID OUT, @FileName, 2, 0, 0
IF @OLEResult <> 0
BEGIN
PRINT 'OpenTextFile'
GOTO Error_Handler
END
--Write Text1
--execute @OLEResult = sp_OAMethod @FileID, 'ReadLine' , @Text1 OUT
--set @Text1='Hello'
execute @OLEResult = sp_OAMethod @FileID, 'WriteLine' ,@r out,'Test'
IF @OLEResult <> 0
BEGIN
PRINT 'ReadLine'
GOTO Error_Handler
END
SELECT @Text1

Error_Handler:
PRINT '*** ERROR ***'
EXEC sp_OAGetErrorInfo null, @source OUT, @desc OUT
SELECT hr = CONVERT (binary(4), @hr), source = @source, description = @desc
Done:
EXECUTE @OLEResult = sp_OADestroy @FileID
EXECUTE @OLEResult = sp_OADestroy @FS

Файл открывается, но при попытке записи возникает ошибка
Error in parameters, or attempt to retrieve a return value from a method that doesn't supply one.

Вроде все параметры передаю, но что еще надо не пойму.
Может у кого есть идеи?
Спасибо
... << RSDN@Home 1.1.4 beta 5 rev. 395>>
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.