We help IT Professionals succeed at work.
Get Started

Reading a file from the filesystem using SQL

Last Modified: 2012-05-09
In a SQL Stored Procedure, I write a file to the filesystem using teh following code:

      @ObjectToken INT
            EXEC sp_configure 'show advanced options', 1
            EXEC sp_configure 'Ole Automation Procedures', 1
             EXEC sp_OACreate 'ADODB.Stream', @ObjectToken OUTPUT
            EXEC sp_OASetProperty @ObjectToken, 'Type', 1
            EXEC sp_OAMethod @ObjectToken, 'Open'
            EXEC sp_OAMethod @ObjectToken, 'Write', NULL, @dataToWrite
            EXEC sp_OAMethod @ObjectToken, 'SaveToFile', NULL, 'filename', 2
            EXEC sp_OAMethod @ObjectToken, 'Close'
            EXEC sp_OADestroy @ObjectToken

            EXEC sp_configure 'Ole Automation Procedures', 0
            EXEC sp_configure 'show advanced options', 0

Now, if I want to READ a file FROM teh filesystem, how do I go about that?!?!?!

Watch Question
This problem has been solved!
Unlock 2 Answers and 6 Comments.
See Answers
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE