Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Create text file

Author  Topic 

iminore
Posting Yak Master

141 Posts

Posted - 2005-07-19 : 15:46:41
I cannot get this to work. Should it?

declare @fileid int, @path varchar(400), @hr int

set @path='c:\bs\ttt.txt'

exec @hr = sp_OACreate 'Scripting.FileSystemObject', @fileid OUT
if @hr = 0
begin
exec @hr = sp_OAMethod @fileid, 'OpentextFile' , @path, 2, 'true'
end

timmy
Master Smack Fu Yak Hacker

1242 Posts

Posted - 2005-07-19 : 19:00:58
You need to pass in the pointer where the file reference will be created:
exec @hr = sp_OAMethod @fileid, 'CreateTextFile', @file OUT, @path, 0, 'true'

Then it works (@file is an INT btw)

FYI - You can use
EXEC sp_OAGetErrorInfo @fileid
to get proper error codes if you want.

HTH,

Tim
Go to Top of Page

iminore
Posting Yak Master

141 Posts

Posted - 2005-07-20 : 01:55:26
Timmy - you're a wonder.

The day before I take my sister to Heathrow to fly back to Perth and before the Ashes start I'm helped by an Aussie. God moves in mysterious ways ...
Go to Top of Page
   

- Advertisement -