Results 1 to 7 of 7

Thread: Error When Selecting Data from Blob

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    71

    Error When Selecting Data from Blob

    hello everybody

    i am trying to insert an image into oracle database but i am getting an unspecified error.here is my code fot the same
    VB Code:
    1. 'Public Function SaveImage()
    2. '
    3. 'Dim PictBmp As String
    4. 'Dim ByteData() As Byte
    5. 'Dim SourceFile As Integer
    6. '
    7. 'PictBmp = "C:\z123456.jpg"
    8. '
    9. 'With cn
    10. '    .Provider = "MSDASQL.1"
    11. '    .cnectionString = "Password=test;Persist Security Info=True;User ID=test;Data Source=test123"
    12. '    .Open
    13. 'End With
    14. '
    15. '
    16. '
    17. ''With rs
    18. ''    .Activecnection = cn
    19. ''    .CursorType = adOpenKeyset
    20. ''    .LockType = adLockOptimistic
    21. ''    .Source = "SELECT IMG FROM CAMERA_IMG WHERE SRNO = 1"
    22. ''    .Open
    23. ''End With
    24. '
    25. 'SourceFile = FreeFile
    26. 'Open PictBmp For Binary Access Read As SourceFile
    27. 'FileLength = LOF(SourceFile)
    28. 'Dim FileMgr As New FileManager
    29. '
    30. 'If FileLength = 0 Then
    31. '    Close SourceFile
    32. '
    33. 'Else
    34. '    Numblocks = FileLength / BlockSize
    35. '    LeftOver = FileLength Mod BlockSize
    36. '
    37. '    ReDim ByteData(LeftOver)
    38. '     Get SourceFile, , ByteData()
    39. '     rs(1).AppendChunk ByteData()
    40. '
    41. '     ReDim ByteData(BlockSize)
    42. '     For i = 1 To Numblocks
    43. '         Get SourceFile, , ByteData()
    44. '         rs(1).AppendChunk ByteData()
    45. '     Next i
    46. '
    47. '     rs.Update   'Commit the new data.
    48. '
    49. '    Close SourceFile
    50. 'End If
    51. '
    52. '
    53. 'End Function
    i am getting the unspecified error(-2147467259) on the Select statement.I have oracle 9i as my database and thre is one BLOB field called IMG in the table.I am using ADO 2.6 library.

    parth
    Last edited by Hack; Mar 16th, 2006 at 08:14 AM. Reason: Added [vbcode] [/vbcode] tags for more clarity.

  2. #2
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Error When Selecting Data from Blob

    Check the cn.Errors collection as well.
    I think they will be more descriptive.
    Frans

  3. #3
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Error When Selecting Data from Blob

    Why is all your code commented out? (and not in VBCode tags so we can read it easily?)


    Anyway.. you can't use a BLOB field in the same way as other fields, for an example see the thread How can I store images (or other files) in a database? from the Database Development FAQ.

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Sep 2005
    Posts
    71

    Re: Error When Selecting Data from Blob

    i tried cn.errors but it did not work out.i have read somewhere that ADO cannot insert data into BLOB but only in LONG RAW data type.Is this true??anyways here is my code without comments.

    Public Function SaveImage()

    Dim PictBmp As String
    Dim ByteData() As Byte
    Dim SourceFile As Integer

    PictBmp = "C:\z123456_2006-03-14.jpg"

    With cn
    .Provider = "MSDASQL.1"
    .ConnectionString = "Password=test;Persist Security Info=True;User ID=test;Data Source=test123"
    .Open
    End With


    strSQL = "INSERT INTO CAMERA_IMG(SRNO,IMG) " & _
    "VALUES (1,EMPTY_BLOB())"

    With cn
    .BeginTrans
    .Execute strSQL
    .CommitTrans
    End With

    strSQL = "SELECT SRNO,IMG FROM CAMERA_IMG WHERE SRNO = 1"
    Set rs = New ADODB.Recordset
    rs.CursorType = adOpenKeyset
    rs.LockType = adLockOptimistic
    rs.Open strSQL, cn
    MsgBox cn.Errors

    SourceFile = FreeFile
    Open PictBmp For Binary Access Read As SourceFile
    FileLength = LOF(SourceFile)

    If FileLength = 0 Then
    Close SourceFile

    Else
    Numblocks = FileLength / BlockSize
    LeftOver = FileLength Mod BlockSize

    ReDim ByteData(LeftOver)
    Get SourceFile, , ByteData()
    rs(1).AppendChunk ByteData()

    ReDim ByteData(BlockSize)
    For i = 1 To Numblocks
    Get SourceFile, , ByteData()
    rs(1).AppendChunk ByteData()
    Next i

    rs.Update 'Commit the new data.

    Close SourceFile
    End If


    End Function

  5. #5
    Software Carpenter dee-u's Avatar
    Join Date
    Feb 2005
    Location
    Pinas
    Posts
    11,127

    Re: Error When Selecting Data from Blob

    For BLOB try using the AddNew method of the recordset object instead of "Insert Into..."
    Regards,


    As a gesture of gratitude please consider rating helpful posts. c",)

    Some stuffs: Mouse Hotkey | Compress file using SQL Server! | WPF - Rounded Combobox | WPF - Notify Icon and Balloon | NetVerser - a WPF chatting system

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Error When Selecting Data from Blob

    I'm afraid I have no idea what you mean about cn.Errors.

    One thing tho, why are you using "EMPTY_BLOB()" in your SQL, rather than "Null"?

    Also, why does the transaction only cover the Insert Into, as opposed to the entire routine? (transactions are designed to encompass a whole process, and are irrelevant for a single statement).

  7. #7
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926

    Re: Error When Selecting Data from Blob

    If ADO generated the error, and that is very likely, the Errors collection of the connection object must contain at least one error.

    If you try something like this in the immediate window, when the error occurs, you can get the error description ADO received from the database:

    VB Code:
    1. ?cn.Errors(0).Description

    You can try index 1 as well, if there are more errors.
    Frans

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