# What is wrong in my syntax that makes binary store in MsSQL go wrong?

Hi Experts,

My .vbs script works like a charm but only the binary store of my file (pdf) goes wrong. What am I doing wrong?

Set xmlDOM = CreateObject("MSXML2.DOMDocument")
xmlDOM.async = False
CS = "Provider=SQLOLEDB;Data Source=myhost;Initial Catalog=MyCatalog; User ID=MyAccount; Password=Secret;" ' Deze regel is verantwoordelijk voor de connect naar de MSSQL database
Set folder = XMLDom.SelectNodes("index/folders/folder")
db.open CS
for each folderItem In folder
folderid =folderItem.SelectSingleNode("id").text
foldername=folderItem.SelectSingleNode("name").text
for each documentItem in folderItem.SelectNodes("documents/document")
docid = documentItem.SelectSingleNode("id").text
version = documentItem.SelectSingleNode("version").text
title = documentItem.SelectSingleNode("title").text
extension = documentItem.SelectSingleNode("extension").text
summary = documentItem.SelectSingleNode("summary").text
viewerurl = documentItem.SelectSingleNode("viewerurl").text
Sql = "select * FROM externedocumenten"
RecordSet.Open Sql, CS, 3, 3
RecordSet.Fields("categorieID").Value = folderid
RecordSet.Fields("categorienaam").Value = replace(foldername,"'", "")
RecordSet.Fields("id").Value = docID
RecordSet.Fields("versie").Value = version
RecordSet.Fields("titel").Value = replace(title,"'", "")
RecordSet.Fields("extentie").Value = "application/" & extension
RecordSet.Fields("URL").Value = viewerurl
RecordSet.Fields("bestand").AppendChunk viewerurl
RecordSet.Update
next
next
Set  RecordSet = Nothing
Set xmlDOM = Nothing



The data field "bestand" has data type "image". The field gets filled but not completly or not right.

Kind regards,

Steynsk
LVL 1
###### Who is Participating?

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Web Ninja at largeCommented:
the line

RecordSet.Fields("bestand").AppendChunk viewerurl

doesn't look right, it looks like you're just writing the location of the file to the database. you first need to load the file into memory, then save it to the database.

are you using any 3rd party components like aspUpload?
Author Commented:
Thanks for the quick response. No the files are on the server.
Web Ninja at largeCommented:
No problem :)

What I was asking is if you use a third party tool to help upload and manage files on a server, which is a common approach.
Author Commented:
No the files are put in a directory by an application and then this script triggert by an sceduled task will read the xml and based on the xml info it should fill a table with info from the the xml and store files that came with the xml. So no third party tool is involved.
Web Ninja at largeCommented:
are you opposed to using one if it was free?
Author Commented:
I rather have 100% code sollution instead of a component sollition. And uploading is not needed. The files are on the server.
Web Ninja at largeCommented:
you're going to have to look into using ADODB.Stream, this will allow you to load the file into memory. then you would loop through each "chunk" of the file which will let you to save it to the database.

i don't have any code at the moment see what you can find, and if you cant find anything by tomorrow, I'll see what I can dig up.
Developer & EE ModeratorCommented:
I think you either need to use bulk insert http://www.mssqltips.com/sqlservertip/1207/different-options-for-importing-data-into-sql-server/ or you have to stream the file.  I don's see either.

For the stream probably
Set objStr = Server.CreateObject("ADODB.Stream")
ObjStr.Type = 1
ObjStr.Open
RecordSet.Fields("bestand") = blobFile


Experts Exchange Solution brought to you by

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Developer & EE ModeratorCommented:
This is about the same thing from ms http://support.microsoft.com/kb/194975
Author Commented:
Thanks a lot Scott
Web Ninja at largeCommented:
interesting solution on the bulk insert, didn't think of that, nice one!

if you think of it, can you post back here and let us know if that worked? i'm about to do something similar and may use that approach
###### It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.