Results 1 to 6 of 6

Thread: [RESOLVED] Loading pic from DB (Error Multiple-Step OLE DB)

  1. #1

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Resolved [RESOLVED] Loading pic from DB (Error Multiple-Step OLE DB)

    Hey,

    I found a good example from Rhino Bull on how to load and extract a picture to/from a db. My problem seems to be occuring when i try to extract the picture from the db. I get the Multiple-Step OLE DB Error. I'm using SQL Server.

    VB Code:
    1. 'get all chunks and write then to a temp file
    2.         For block_num = 1 To num_blocks
    3.             [color=#CC0000]bytes() = adoRST.Fields("CARD_PICT_IMAG").GetChunk(BLOCK_SIZE)[/color][color=#CC0000][/color]
    4.             Put #file_num, , bytes()
    5.         Next block_num

    The red line is the one is the one that is bugging me.
    Any help is appreciated.

    Also i want to check and make sure that my loadPic is putting the data into the db field properly. How can i do that?

    Thanks
    Andy
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  2. #2
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Loading pic from DB (Error Multiple-Step OLE DB)

    Looks like something is missing.
    VB Code:
    1. ReDim bytes(BLOCK_SIZE)
    [color=navyOr you may have it dimed to an incorrect chunk size causing an overflow which can be the multistep error.[/color]
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  3. #3

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Loading pic from DB (Error Multiple-Step OLE DB)

    Hey Rob,

    I tried out what you suggested but i got the same result.
    Right now the BLOCK_SIZE is set to 10000 but i've tried at several different things such as, 256 1024. None of which worked.

    VB Code:
    1. file_num = FreeFile
    2.     Open file_name For Binary As #file_num
    3.         ' Copy the data into the file.
    4.         file_length = adoRST.Fields("CARD_PICT_SIZE")
    5.        
    6.         num_blocks = file_length / BLOCK_SIZE
    7.         left_over = file_length Mod BLOCK_SIZE
    8.        
    9.         ReDim bytes(BLOCK_SIZE)
    10.         'get all chunks and write then to a temp file
    11.         For block_num = 1 To num_blocks
    12.             bytes() = adoRST.Fields("CARD_PICT_IMAG").GetChunk(BLOCK_SIZE)
    13.             Put #file_num, , bytes()
    14.         Next block_num
    15.         If left_over > 0 Then
    16.             ReDim bytes(left_over)
    17.             bytes() = adoRST.Fields("CARD_PICT_IMAG").GetChunk(left_over)
    18.             Put #file_num, , bytes()
    19.         End If
    20.     Close #file_num
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  4. #4
    Ex-Super Mod RobDog888's Avatar
    Join Date
    Apr 2001
    Location
    LA, Calif. Raiders #1 AKA:Gangsta Yoda™
    Posts
    60,709

    Re: Loading pic from DB (Error Multiple-Step OLE DB)

    I dont have access to SQL Server currently so its hard to test his example. Is your field type a OLE Object or ?
    VB/Office Guru™ (AKA: Gangsta Yoda®)
    I dont answer coding questions via PM. Please post a thread in the appropriate forum.

    Microsoft MVP 2006-2011
    Office Development FAQ (C#, VB.NET, VB 6, VBA)
    Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
    If a post has helped you then Please Rate it!
    Reps & Rating PostsVS.NET on Vista Multiple .NET Framework Versions Office Primary Interop AssembliesVB/Office Guru™ Word SpellChecker™.NETVB/Office Guru™ Word SpellChecker™ VB6VB.NET Attributes Ex.Outlook Global Address ListAPI Viewer utility.NET API Viewer Utility
    System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6

  5. #5

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Loading pic from DB (Error Multiple-Step OLE DB)

    I don't see an explicit OLE Object Datatype, so i've been using the Image Datatype. Is that incorrect?
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

  6. #6

    Thread Starter
    Fanatic Member space_monkey's Avatar
    Join Date
    Apr 2005
    Location
    神と歩くこと
    Posts
    573

    Re: Loading pic from DB (Error Multiple-Step OLE DB)

    I'm still not sure what i was doing wrong with Rhino's example but here's what i ended up doing. Thanks Rob for trying to help.

    VB Code:
    1. Private Sub LoadPic_DB(ByVal lPicNum As Long)
    2. Dim strFilename As String
    3. Dim rsTemp As adodb.Recordset
    4. Dim strResponse As String
    5. Dim strSQL As String
    6. Dim strTitle As String
    7. Dim adoCmd As adodb.Command
    8. Dim mstream As adodb.Stream
    9.  
    10.     cdMain.ShowOpen
    11.    
    12.     strFilename = cdMain.FileName
    13.  
    14.     strResponse = MsgBox("Are you sure you want to load this picture?", vbInformation + vbYesNo, "LOAD")
    15.  
    16.     If strResponse = vbNo Then
    17.         Exit Sub
    18.     End If
    19.  
    20.     strTitle = UserPermissions.strUserName & "_" & Format(Now, "yyyymmddhhnnss")
    21.  
    22.     strSQL = "Insert into CARD_PICT ([CARD_PICT_ID]) VALUES ('"
    23.     strSQL = strSQL & strTitle & "')"
    24.  
    25.     Set adoCmd = New adodb.Command
    26.  
    27.     With adoCmd
    28.         .CommandText = strSQL
    29.         .CommandType = adCmdText
    30.         .ActiveConnection = strCon
    31.         .Execute
    32.     End With
    33.  
    34.     Set rsTemp = New adodb.Recordset
    35.     rsTemp.Open "CARD_PICT", strCon, adOpenKeyset, adLockPessimistic, adCmdTable
    36.  
    37.     rsTemp.Find "CARD_PICT_ID ='" & strTitle & "'"
    38.    
    39.     rsTemp.Fields("CARD_PICT_TYPE") = Trim(Mid(strFilename, InStr(1, strFilename, ".")))
    40.    
    41.     Set mstream = New adodb.Stream
    42.     mstream.Type = adTypeBinary
    43.     mstream.Open
    44.     mstream.LoadFromFile strFilename
    45.    
    46.     rsTemp.Fields("CARD_PICT_IMAG").Value = mstream.Read
    47.     rsTemp.Update
    48.  
    49.     'AddNewImage rsTemp, strTitle, strFileName
    50.    
    51.     MsgBox "Picture has been added!", vbInformation, "Success"
    52.    
    53.     Select Case lPicNum
    54.         Case 1
    55.             strPic1_ID = strTitle
    56.         Case 2
    57.             strPic2_ID = strTitle
    58.         Case 3
    59.             strPic3_ID = strTitle
    60.     End Select
    61.    
    62.     If rsTemp.State = adStateOpen Then
    63.         rsTemp.Close
    64.         Set rsTemp = Nothing
    65.     End If
    66.  
    67. End Sub
    68.  
    69. Private Sub OpenImage(ByVal lPicNum As Long)
    70. Dim rsTemp As adodb.Recordset
    71. Dim mstream As adodb.Stream
    72. Dim strTitle As String
    73. Dim strFilename As String
    74. Dim strType As String
    75.  
    76.     Set rsTemp = New adodb.Recordset
    77.     rsTemp.Open "CARD_PICT", strCon, adOpenKeyset, adLockPessimistic, adCmdTable
    78.    
    79.     Select Case lPicNum
    80.         Case 1
    81.             strTitle = strPic1_ID
    82.         Case 2
    83.             strTitle = strPic2_ID
    84.         Case 3
    85.             strTitle = strPic3_ID
    86.     End Select
    87.    
    88.  
    89.     rsTemp.Find "CARD_PICT_ID ='" & strTitle & "'"
    90.  
    91.     strType = rsTemp.Fields("CARD_PICT_TYPE")
    92.  
    93.     Set mstream = New adodb.Stream
    94.     mstream.Type = adTypeBinary
    95.     mstream.Open
    96.     mstream.Write rsTemp.Fields("CARD_PICT_IMAG").Value
    97.    
    98.     strFilename = App.Path & "\PICS\" & strTitle & strType
    99.     mstream.SaveToFile strFilename, adSaveCreateOverWrite
    100.    
    101.     Select Case lPicNum
    102.         Case 1
    103.                 img1.Picture = LoadPicture(strFilename)
    104.         Case 2
    105.                 img2.Picture = LoadPicture(strFilename)
    106.         Case 3
    107.                 img3.Picture = LoadPicture(strFilename)
    108.     End Select
    109.    
    110.    
    111.     If rsTemp.State = adStateOpen Then
    112.         rsTemp.Close
    113.         Set rsTemp = Nothing
    114.     End If
    115.  
    116. End Sub
    Using VB6 or VB.net 2008 with .net 3.5
    "Life... death... either way I'll be confined to a small cubicle!" - Hermes Conrad

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width