[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 265
  • Last Modified:

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
0
Steynsk
Asked:
Steynsk
  • 5
  • 4
  • 2
1 Solution
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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?
0
 
SteynskAuthor Commented:
Thanks for the quick response. No the files are on the server.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
are you opposed to using one if it was free?
0
 
SteynskAuthor Commented:
I rather have 100% code sollution instead of a component sollition. And uploading is not needed. The files are on the server.
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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.
0
 
Scott Fell, EE MVEDeveloperCommented:
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

0
 
Scott Fell, EE MVEDeveloperCommented:
This is about the same thing from ms http://support.microsoft.com/kb/194975
0
 
SteynskAuthor Commented:
Thanks a lot Scott
0
 
Big MontySenior Web Developer / CEO of ExchangeTree.org Commented:
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
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

  • 5
  • 4
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now