Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Write field to a file of type html

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
An alternative to the "For XML" way of pivoting and concatenating result sets into strings, and an easy introduction to "common table expressions" (CTEs). Being someone who is always looking for alternatives to "work your data", I came across this …
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.

715 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