[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 200
  • Last Modified:

SQL 2005: Problem with office automation

I'm using the attached code.  Works fine on SQL 2000 but not on SQL 2005.  I have enabled office automation on the server for SQL 2005.  It seems my variable @OLE is implemented.  The line

if @OLE <> 0  always executes, the variable is never 0.  Please help!
EXECUTE @OLE = sp_OACreate 'Scripting.FileSystemObject', @FS OUT
IF @OLE <> 0 PRINT 'Scripting.FileSystemObject'
 
--Open a file
execute @OLE = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @FileLocTXT, 2, 1
--IF @OLE <> 0 PRINT 'ERROR'
EXEC @OLE = sp_OAGetErrorInfo @FS, @source OUT, @description OUT
If @OLE <> 0
BEGIN
	PRINT 'OLE Automation Error Information'
	EXEC @OLE = sp_OAGetErrorInfo @FS, @source OUT, @description OUT
	SELECT @output = '  Source: ' + @source
    PRINT @output
	SELECT @output = '  Description: ' + @description
    PRINT @output
END
ELSE
BEGIN
    PRINT '  sp_OAGetErrorInfo failed.'
    RETURN
END

Open in new window

0
jasonbrandt3
Asked:
jasonbrandt3
  • 2
1 Solution
 
ralmadaCommented:

The correct way of calling a stored procedure is

execute sp_OAMethod @OLE = @FS OUTPUT,...
I'm assuming that @FS is the output parameter that contains the value you are looking for. If not change it for the required one.
0
 
bull_riderCommented:
Check out if the OLE Automation feature has been enabled in SQL surface Area configuration. The other thing which you can verify is that the path should be accessible by the user logged in. I mean the shared folder. I dont find any other discrepancies in the code. And still if it does not work, try using a print statement for the @OLE variable and give me the exact error number. You can go through the below link, to find out the error.

http://msdn.microsoft.com/en-us/library/ms189556(SQL.90).aspx
0
 
bull_riderCommented:
And one more thing, can you try out changing the sp_OAMethod statement to this:
execute @OLE = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @FileLocTXT, 8, 1

I have just changed the 2 to 8. Let me know if it worked.


0

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now