Link to home
Start Free TrialLog in
Avatar of Steynsk
SteynskFlag for Netherlands

asked on

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
Avatar of Big Monty
Big Monty
Flag of United States of America image

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?
Avatar of Steynsk

ASKER

Thanks for the quick response. No the files are on the server.
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.
Avatar of Steynsk

ASKER

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.
are you opposed to using one if it was free?
Avatar of Steynsk

ASKER

I rather have 100% code sollution instead of a component sollition. And uploading is not needed. The files are on the server.
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.
ASKER CERTIFIED SOLUTION
Avatar of Scott Fell
Scott Fell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
This is about the same thing from ms http://support.microsoft.com/kb/194975
Avatar of Steynsk

ASKER

Thanks a lot Scott
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