Home All Groups Group Topic Archive Search About

Extracting documents from a database

Author
9 Oct 2007 4:51 PM
PhilHibbs
How do I extract documents from a SQL Server database? I'm off ill so
I don't have the table structure to hand but I'm pretty sure there's
some kind of BLOB field and a text field with the document name, I'm
not sure whether they are Word documents of PDFs but I don't suppose
that makes much difference.

There are a lot of documents to extract, and I'd like to do it as an
iSQL script that just extracts every document in the database. How do
I do this? I'm a little more familiar with Oracle SQL*Plus than I am
with MS, but I've also used Sybase before.

Phil.

Author
9 Oct 2007 9:15 PM
Erland Sommarskog
PhilHibbs (sna***@gmail.com) writes:
> How do I extract documents from a SQL Server database? I'm off ill so
> I don't have the table structure to hand but I'm pretty sure there's
> some kind of BLOB field and a text field with the document name, I'm
> not sure whether they are Word documents of PDFs but I don't suppose
> that makes much difference.
>
> There are a lot of documents to extract, and I'd like to do it as an
> iSQL script that just extracts every document in the database. How do
> I do this? I'm a little more familiar with Oracle SQL*Plus than I am
> with MS, but I've also used Sybase before.

The best is probably to write a small program in C# or VB .Net. I have
a very quick example on http://www.sommarskog.se/blobload.txt that you can
work from.

You can't really do it in an SQL script, because an SQL script can't write
to a file. You could use BCP for the task, but then you would need something
to drive BCP, as you would have to run BCP once for each document.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Author
13 Oct 2007 3:16 AM
Linchi Shea
You can try a command utility called textcopy.exe that you can find in the
BINN directory of a SQL2000 instance. At the command line, type textcopy -?
will give the command line usage. The -O option is for exporting a text or
image value.

For an example of how it can be used, you can find it is used to import
text/image files in two batch files in the Install directory of a SQL2000
instance. The two batch files are pubtext.bat and pubimage.bat, respectively.

Linchi

Show quote
"PhilHibbs" wrote:

> How do I extract documents from a SQL Server database? I'm off ill so
> I don't have the table structure to hand but I'm pretty sure there's
> some kind of BLOB field and a text field with the document name, I'm
> not sure whether they are Word documents of PDFs but I don't suppose
> that makes much difference.
>
> There are a lot of documents to extract, and I'd like to do it as an
> iSQL script that just extracts every document in the database. How do
> I do this? I'm a little more familiar with Oracle SQL*Plus than I am
> with MS, but I've also used Sybase before.
>
> Phil.
>
>
Author
16 Oct 2007 11:26 AM
PhilHibbs
On 13 Oct, 04:16, Linchi Shea <LinchiS***@discussions.microsoft.com>
wrote:
> You can try a command utility called textcopy.exe that you can find in the
> BINN directory of a SQL2000 instance. At the command line, type textcopy -?
> will give the command line usage. The -O option is for exporting a text or
> image value.

No luck, doesn't seem to be there in SQL Server 2005.

Phil Hibbs.
Author
16 Oct 2007 9:55 PM
Erland Sommarskog
PhilHibbs (sna***@gmail.com) writes:
> On 13 Oct, 04:16, Linchi Shea <LinchiS***@discussions.microsoft.com>
> wrote:
>> You can try a command utility called textcopy.exe that you can find in
>> the BINN directory of a SQL2000 instance. At the command line, type
>> textcopy -? will give the command line usage. The -O option is for
>> exporting a text or image value.
>
> No luck, doesn't seem to be there in SQL Server 2005.

If you can find an SQL 2000 installation CD, you can get the samples
from that CD and build textcopy yourself. You will need to put
NTWDBLIB.DLL in system32 on the SQL 2005 machine, since SQL 2005 does
not come with any files for DB-Library.

Then again, writing a simple .Net app that performs the work of
textcopy should not be a big deal. It's a lot easier in .Net than
with DB-Library. I have a quick demo at
http://www.sommarskog.se/blobload.txt.


--
Erland Sommarskog, SQL Server MVP, esq***@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

AddThis Social Bookmark Button