Solved

SQL 2005:  Problem with office automation

Posted on 2009-05-11
3
189 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
sql query help 2 62
create insert script based on records in a table 4 28
Find data in a column which is not in  a date format 29 36
SQL query with cast 38 59
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…
In this article I will describe the Copy Database Wizard method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

749 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