Solved

SQL 2005:  Problem with office automation

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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
T-SQL to Update Table Dynamically 2 72
Restrict result set 1 47
Email Notifications for SQL 2005 9 42
What is this datetime? 1 33
I am showing a way to read/import the excel data in table using SQL server 2005... Suppose there is an Excel file "Book1" at location "C:\temp" with column "First Name" and "Last Name". Now to import this Excel data into the table, we will use…
So every once in a while at work I am asked to export data from one table and insert it into another on a different server.  I hate doing this.  There's so many different tables and data types.  Some column data needs quoted and some doesn't.  What …
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

737 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