keyword: UPDATETEXT
Recordset With/Without AppendChunk is unusable to store large binary data to MS SQL (>10th of MB). We have to use native MS SQL methods - UPDATETEXT command.
I used the same code with Recordset to store extra upload field - client IP, description, ... As a result of it I have UploadID - primary key of row, which has zero length of binary field named 'Data'
'Process source data using blocks
Dim BlockCounter, HexDataBlock
For BlockCounter = 0 To Form("DBFile").Length Step BlockSize
'Get a part of source data as a Hex string
HexDataBlock = Form("DBFile").HexString(BlockCounter, BlockSize)
'Add a part of source data to the field using SQL UPDATETEXT command
SQL = "DECLARE @dataptr binary(16)" & vbCrLf
SQL = SQL & "SELECT @dataptr = TEXTPTR(Data)"
SQL = SQL & " FROM Upload WHERE UploadID=" & UploadID & vbCrLf
SQL = SQL & "UPDATETEXT Upload.Data @dataptr " & BlockCounter & " NULL 0x" & HexDataBlock
'Execute prepared SQL command
Conn.Execute SQL, 0, adCmdText + adExecuteNoRecords
Next 'BlockCounter
And how this code works? For example 100MB file. Uploaded data are stored on the disk. We add another fields of upload record to the database (some bytes/kB).
Then we process source binary data using blocks. HexString reads 1MB of source data from the disk, converts this data to HexString (+4MB - Unicode HexString), creates UPDATETEXT SQL (+4MB) and sends this SQL command to MS SQL. MS SQL gets this string (+10MB ADO +2MB in SQL) converts it to binary data (+1MB) and the data are stored to the database file.
This code takes constant amount of memory - the amount of memory depends on source block size. For 1MB block - VBS code takes 8MB of memory; ADO Execute method takes 10MB (I do not know why such big amount).
Although this code takes a big amount of processor time, I test it to store files with up to 512MB of size.
http://www.pstruh.cz/help/scptutl/pa28.htm
单独写了个测试程序,丢开网络传输,在本机上试,BLOB字段超过60M后,同样内存占用很大,机器运行奇慢,执行到Update()处,就出现异常.是不是SQL SERVER 对BLOB支持不好?因为连到本机的ACCESS数据库,400M的数据都插进去了,当然插入时机器反应慢,但不致于象SQL SERVER一样慢和插不了,内存也不见猛耗.盼有过此方面经验的同仁相助!!!!!!!!