Solved

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

Posted on 2014-07-10
256 Views
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
0
Question by:Steynsk

LVL 32

Expert Comment

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

LVL 1

Author Comment

Thanks for the quick response. No the files are on the server.
0

LVL 32

Expert Comment

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

LVL 1

Author Comment

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

LVL 32

Expert Comment

are you opposed to using one if it was free?
0

LVL 1

Author Comment

I rather have 100% code sollution instead of a component sollition. And uploading is not needed. The files are on the server.
0

LVL 32

Expert Comment

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

LVL 52

Accepted Solution

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

0

LVL 52

Expert Comment

This is about the same thing from ms http://support.microsoft.com/kb/194975
0

LVL 1

Author Closing Comment

Thanks a lot Scott
0

LVL 32

Expert Comment

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

Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…