I have a varbinary(max) column in a SQL Server table. I am trying to
populate it through VBA code.
The code fails when the update to this column is done with a large
file and in a linked table environment in MS Access.
The linking is done using an ODBC system DSN. It is interesting that
the code works fine with smaller files.
Const conChunkSize = 64000
Sub LoadJobOutputFileIntoDatabase(nJobPK&, strRe****tFile$)
Dim Rcd As New ADODB.Recordset
Dim strTempA$
Dim nOffset&
Dim strChunk As String
Dim nLOBSize&
strTempA = LoadFileIntoString(strRe****tFile)
Rcd.Open "select * from brick_job where brick_job_pk=" & nJobPK,
CurrentProject.Connection, adOpenKeyset, adLockOptimistic
nOffset = 0 ' Reset offset
nLOBSize = LenB(strTempA)
Do While nOffset < nLOBSize
strChunk = LeftB(RightB(strTempA, nLOBSize - nOffset), _
conChunkSize)
Rcd!job_output.AppendChunk strChunk
nOffset = nOffset + conChunkSize
Loop
Rcd.Update 'THIS STATEMENT GIVES RUN TIME ERROR
-2147217887(80040e21)
End Sub
However, the code works fine with ADO OLE Provider connection string.
Sub LoadJobOutputFileIntoDatabase(nJobPK&, strRe****tFile$)
Dim Conn As New ADODB.Connection
Dim Rcd As New ADODB.Recordset
Dim strTempA$
Dim nOffset&
Dim strChunk As String
Dim nLOBSize&
Conn.Open "Provider=SQLOLEDB.1;User ID=user1;Password=pwd1;Initial
Catalog=Brickrpt;Data Source=butthead"
strTempA = LoadFileIntoString(strRe****tFile)
Rcd.Open "select * from brick_job where brick_job_pk=" & nJobPK,
Conn, adOpenKeyset, adLockOptimistic
nOffset = 0 ' Reset offset
nLOBSize = LenB(strTempA)
Do While nOffset < nLOBSize
strChunk = LeftB(RightB(strTempA, nLOBSize - nOffset), _
conChunkSize)
Rcd!job_output.AppendChunk strChunk
nOffset = nOffset + conChunkSize
Loop
Rcd.Update
End Sub
Function LoadFileIntoString$(strFileName$)
Dim nFile%, strTemp$, nFileLen&, strRec$, nCnt1&
Const constBuffSize& = 2000000
On Error GoTo LoadFileIntoString_Err
LoadFileIntoString = ""
nFile = FreeFile
strRec = ""
Open strFileName For Binary Access Read As #nFile
nCnt1 = 0
nFileLen = FileLen(strFileName)
Do While True
If EOF(nFile) Then
Exit Do
End If
strTemp = Space(constBuffSize)
Get #nFile, , strTemp
If (nCnt1 + constBuffSize) > nFileLen Then
strTemp = Mid(strTemp, 1, (nFileLen - nCnt1))
End If
strRec = strRec & strTemp
nCnt1 = nCnt1 + Len(strTemp)
Loop
Close #nFile
LoadFileIntoString = strRec
Exit Function
LoadFileIntoString_Err:
If nFile > 0 Then
Close #nFile
End If
Exit Function
End Function
So, the question is, is there a limit on varbinary columns sup****ted
through ODBC? If no then how I can fix the error. I will appreciate
the help.
Ash


|