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
xmlDOM.Load "D:\index.xml"
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")
Set db = CreateObject("ADODB.Connection")
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"
                        Set RecordSet = CreateObject("ADODB.Recordset")
                        RecordSet.Open Sql, CS, 3, 3
                        RecordSet.AddNew
                        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
 

Open in new window


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

Kind regards,

Steynsk
LVL 1
SteynskAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

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.

Big MontyWeb 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?
SteynskAuthor Commented:
Thanks for the quick response. No the files are on the server.
Big MontyWeb 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.
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

SteynskAuthor 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.
Big MontyWeb Ninja at largeCommented:
are you opposed to using one if it was free?
SteynskAuthor Commented:
I rather have 100% code sollution instead of a component sollition. And uploading is not needed. The files are on the server.
Big MontyWeb 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.
Scott Fell, EE MVEDeveloper & 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
ObjStr.LoadFromFile "c:\path\to\file.pdf"
blobFile = ObjStr.Read
RecordSet.Fields("bestand") = blobFile

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

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

Start your 7-day free trial
Scott Fell, EE MVEDeveloper & EE ModeratorCommented:
This is about the same thing from ms http://support.microsoft.com/kb/194975
SteynskAuthor Commented:
Thanks a lot Scott
Big MontyWeb 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.