Solved

SQL 2005:  Problem with office automation

Posted on 2009-05-11
3
185 Views
Last Modified: 2012-05-06
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
Comment
Question by:jasonbrandt3
  • 2
3 Comments
 
LVL 41

Expert Comment

by:ralmada
Comment Utility

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
 
LVL 6

Accepted Solution

by:
bull_rider earned 500 total points
Comment Utility
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
 
LVL 6

Expert Comment

by:bull_rider
Comment Utility
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

Backup Your Microsoft Windows Server®

Backup all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Join & Write a Comment

This article will describe one method to parse a delimited string into a table of data.   Why would I do that you ask?  Let's say that you need to pass multiple parameters into a stored procedure to search for.  For our sake, we'll say that we wa…
INTRODUCTION: While tying your database objects into builds and your enterprise source control system takes a third-party product (like Visual Studio Database Edition or Red-Gate's SQL Source Control), you can achieve some protection using a sing…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now