Solved

SQL 2005:  Problem with office automation

Posted on 2009-05-11
3
191 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 41

Expert Comment

by:ralmada
ID: 24354799

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
ID: 24354801
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
ID: 24354854
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

Ransomware: The New Cyber Threat & How to Stop It

This infographic explains ransomware, type of malware that blocks access to your files or your systems and holds them hostage until a ransom is paid. It also examines the different types of ransomware and explains what you can do to thwart this sinister online threat.  

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you having speed problem in loading SQL Server Management Studio, try to uncheck these options in your internet browser (IE -> Internet Options / Advanced / Security):    . Check for publisher's certificate revocation    . Check for server ce…
Data architecture is an important aspect in Software as a Service (SaaS) delivery model. This article is a study on the database of a single-tenant application that could be extended to support multiple tenants. The application is web-based develope…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
There's a multitude of different network monitoring solutions out there, and you're probably wondering what makes NetCrunch so special. It's completely agentless, but does let you create an agent, if you desire. It offers powerful scalability …

718 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