Windows Vista Forums
Vista Forums Home Join Vista Forums Windows 7 Forum Vista Tutorials Tags
Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks.

Go Back   Vista Forums > Misc Newsgroups > VB Script

Vista - Saving files from SQL database to file server

Reply
 
Old 08-07-2009   #1 (permalink)
bnick22


 
 

Saving files from SQL database to file server

I have a SQL database table with files stored using the varbinary data type.
I want to loop through this table and save all of the files to my file
server. Connecting to the table and looping through it is no problem; I'm
just looking for proper syntax for saving each file.

I have the following fields (others also, but I figure these might be the
important ones here):

Contents - varbinary(max)
MimeTypeDescription - nvarchar(255)
Filename (This isn't a unique identifier in this case, so at best I can use
it to find the original extension of the file.)
UniqueName (which I'll have to use for the filename)

Can anyone give me a code snippet that will get me started?

Thanks

My System SpecsSystem Spec
Old 08-07-2009   #2 (permalink)
Bob Barrows


 
 

Re: Saving files from SQL database to file server

bnick22 wrote:
Quote:

> I have a SQL database table with files stored using the varbinary
> data type. I want to loop through this table and save all of the
> files to my file server. Connecting to the table and looping through
> it is no problem; I'm just looking for proper syntax for saving each
> file.
>
> I have the following fields (others also, but I figure these might be
> the important ones here):
>
> Contents - varbinary(max)
> MimeTypeDescription - nvarchar(255)
> Filename (This isn't a unique identifier in this case, so at best I
> can use it to find the original extension of the file.)
> UniqueName (which I'll have to use for the filename)
>
> Can anyone give me a code snippet that will get me started?
>
In what context are you doing this? A vbs file on your desktop? Or vbscript
in an ASP file?

--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Old 08-07-2009   #3 (permalink)
bnick22


 
 

Re: Saving files from SQL database to file server

VBScript file run from Windows. I have some experience with ASP.NET (VB), but
the rest of the script is running in a simple .vbs file, and I'd like to
simply append that.

"Bob Barrows" wrote:
Quote:

> bnick22 wrote:
Quote:

> > I have a SQL database table with files stored using the varbinary
> > data type. I want to loop through this table and save all of the
> > files to my file server. Connecting to the table and looping through
> > it is no problem; I'm just looking for proper syntax for saving each
> > file.
> >
> > I have the following fields (others also, but I figure these might be
> > the important ones here):
> >
> > Contents - varbinary(max)
> > MimeTypeDescription - nvarchar(255)
> > Filename (This isn't a unique identifier in this case, so at best I
> > can use it to find the original extension of the file.)
> > UniqueName (which I'll have to use for the filename)
> >
> > Can anyone give me a code snippet that will get me started?
> >
> In what context are you doing this? A vbs file on your desktop? Or vbscript
> in an ASP file?
>
> --
> Microsoft MVP - ASP/ASP.NET - 2004-2007
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
>
My System SpecsSystem Spec
Old 08-07-2009   #4 (permalink)
Bob Barrows


 
 

Re: Saving files from SQL database to file server

Well, the general idea is to use an ADO stream object to capture the binary
output from the field and then use the SaveToFile method to save it to a
file. I believe there may be an example in the ADO documentation which you
can read here:
http://msdn2.microsoft.com/en-us/library/ms675532.aspx

More examples can be found via this google search:
http://www.google.com/search?rlz=1C1...rom+SQL+Server

bnick22 wrote:
Quote:

> VBScript file run from Windows. I have some experience with ASP.NET
> (VB), but the rest of the script is running in a simple .vbs file,
> and I'd like to simply append that.
>
> "Bob Barrows" wrote:
>
Quote:

>> bnick22 wrote:
Quote:

>>> I have a SQL database table with files stored using the varbinary
>>> data type. I want to loop through this table and save all of the
>>> files to my file server. Connecting to the table and looping through
>>> it is no problem; I'm just looking for proper syntax for saving each
>>> file.
>>>
>>> I have the following fields (others also, but I figure these might
>>> be
>>> the important ones here):
>>>
>>> Contents - varbinary(max)
>>> MimeTypeDescription - nvarchar(255)
>>> Filename (This isn't a unique identifier in this case, so at best I
>>> can use it to find the original extension of the file.)
>>> UniqueName (which I'll have to use for the filename)
>>>
>>> Can anyone give me a code snippet that will get me started?
>>>
>> In what context are you doing this? A vbs file on your desktop? Or
>> vbscript in an ASP file?
>>
>> --
>> Microsoft MVP - ASP/ASP.NET - 2004-2007
>> Please reply to the newsgroup. This email account is my spam trap so
>> I don't check it very often. If you must reply off-line, then remove
>> the "NO SPAM"
--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


My System SpecsSystem Spec
Old 08-07-2009   #5 (permalink)
bnick22


 
 

Re: Saving files from SQL database to file server

Thanks very much for the help, Bob. You gave me enough information to find an
answer. I adapted the code I found at
http://www.tech-archive.net/Archive/.../msg00300.html.

"Bob Barrows" wrote:
Quote:

> Well, the general idea is to use an ADO stream object to capture the binary
> output from the field and then use the SaveToFile method to save it to a
> file. I believe there may be an example in the ADO documentation which you
> can read here:
> http://msdn2.microsoft.com/en-us/library/ms675532.aspx
>
> More examples can be found via this google search:
> http://www.google.com/search?rlz=1C1...rom+SQL+Server
>
> bnick22 wrote:
Quote:

> > VBScript file run from Windows. I have some experience with ASP.NET
> > (VB), but the rest of the script is running in a simple .vbs file,
> > and I'd like to simply append that.
> >
> > "Bob Barrows" wrote:
> >
Quote:

> >> bnick22 wrote:
> >>> I have a SQL database table with files stored using the varbinary
> >>> data type. I want to loop through this table and save all of the
> >>> files to my file server. Connecting to the table and looping through
> >>> it is no problem; I'm just looking for proper syntax for saving each
> >>> file.
> >>>
> >>> I have the following fields (others also, but I figure these might
> >>> be
> >>> the important ones here):
> >>>
> >>> Contents - varbinary(max)
> >>> MimeTypeDescription - nvarchar(255)
> >>> Filename (This isn't a unique identifier in this case, so at best I
> >>> can use it to find the original extension of the file.)
> >>> UniqueName (which I'll have to use for the filename)
> >>>
> >>> Can anyone give me a code snippet that will get me started?
> >>>
> >> In what context are you doing this? A vbs file on your desktop? Or
> >> vbscript in an ASP file?
> >>
> >> --
> >> Microsoft MVP - ASP/ASP.NET - 2004-2007
> >> Please reply to the newsgroup. This email account is my spam trap so
> >> I don't check it very often. If you must reply off-line, then remove
> >> the "NO SPAM"
>
> --
> Microsoft MVP - ASP/ASP.NET - 2004-2007
> Please reply to the newsgroup. This email account is my spam trap so I
> don't check it very often. If you must reply off-line, then remove the
> "NO SPAM"
>
>
>
My System SpecsSystem Spec
Reply

Thread Tools


Similar Threads
Thread Forum
Convert Database content into a file on the server VB Script
Saving Data to a Disconnected (Temporarily Unreachable) Database .NET General
Re: ASP.NET web server and sql database server on a old computer .NET General
iis 5.1 can't connect to database server .NET General
XP not saving File Properties Summary for jpeg files Vista file management


Vista Forums is an independent web site and has not been authorized,
sponsored, or otherwise approved by Microsoft Corporation.
"Windows Vista", the Start Orb, and related materials are trademarks of Microsoft Corp.
© Designer Media Ltd

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46