Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Write field to a file of type html

Posted on 2008-06-16
4
Medium Priority
?
812 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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
This month, Experts Exchange sat down with resident SQL expert, Jim Horn, for an in-depth look into the makings of a successful career in SQL.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

916 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