Solved

Write field to a file of type html

Posted on 2008-06-16
4
758 Views
Last Modified: 2008-06-25
I have HTML text in a field.  I need to get it into a file on my server.

I am using the attached SQL code in a SPROC and need help getting it running.  By now I have completely screwed it up, so please set me straight.  At present I am getting an error -2146828212 on the 'OpenTextFile' and an error -2147211483 on the WriteLine

@AttachmentHTMLContent has already been correctly loaded with the data I want to write
@EmailAttachmentFileLocation has the full path to the filename I want to use (e.g. "D:\Folder1\Folder2\Folder3\Folder4\Folder5\Sample Doc.html")


EXECUTE @OLEResult = sp_OACreate 'Scripting.FileSystemObject', @FS OUT

PRINT @OLEResult

IF @OLEResult <> 0 PRINT 'Scripting.FileSystemObject got an error'
 

--Open a file

execute @OLEResult = sp_OAMethod @FS, 'OpenTextFile', @FileID OUT, @EmailAttachmentFileLocation, 8, 1

PRINT @OLEResult

IF @OLEResult <> 0 PRINT 'OpenTextFile got an error'
 

--Write Text1

execute @OLEResult = sp_OAMethod @FileID, 'WriteLine', Null, @AttachmentHTMLContent

PRINT @OLEResult

IF @OLEResult <> 0 PRINT 'WriteLine got an error'

EXECUTE @OLEResult = sp_OADestroy @FileID

EXECUTE @OLEResult = sp_OADestroy @FS

Open in new window

0
Comment
Question by:wsturdev
  • 2
  • 2
4 Comments
 
LVL 7

Expert Comment

by:alexpercsi
ID: 21798146
Do you have to use SQL Server for this? Couldn't you use ASP.NET or another web server technology?
It's really just 5 lines of code in C#.
0
 
LVL 1

Author Comment

by:wsturdev
ID: 21798402
Sorry - can't change.
0
 
LVL 1

Accepted Solution

by:
wsturdev earned 0 total points
ID: 21798632
Stupid, Stupid, Stupid.....

I had the wrong path specified in @EmailAttachmentFileLocation !!!

Problem solved!
0
 
LVL 7

Expert Comment

by:alexpercsi
ID: 21800197
I'm glad it worked out for you :)
0

Featured Post

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Need Counts 11 43
how to fix this error 14 48
shrink datafile Sql server 4 18
Stored Procedure 2 0
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

747 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

11 Experts available now in Live!

Get 1:1 Help Now