A safe array of bytes is expected as an argument

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dooza

    #1

    A safe array of bytes is expected as an argument

    Hi there,
    I am using the ASP to PDF component from www.asppdf.com and have an
    unusual problem when displaying a blob from the database.

    When there is an image stored in my SQL2000 field of type image, and I
    use this:

    Params = "x=337; y=408; scalex=.33; scaley=.33"
    Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
    Page.Canvas.Dra wImage SigImage, Params

    The image gets drawn in the PDF and everything is fine.

    If I try to create a PDF using the same record, but where the image
    filed is NULL, I get this error:

    Persits.PdfMana ger.1 error '800a002f'

    A safe array of bytes is expected as an argument.

    So I thought I need to check if the field isn't null before attempting
    to draw it onto the canvas, so I tried this:

    If LEN(rsMotor("Ph oto").Value) 0 Then
    'Insert Photo
    Params = "x=337; y=408; scalex=.33; scaley=.33"
    Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
    Page.Canvas.Dra wImage SigImage, Params
    End if

    Using this with an image stored in the field gives me the same error
    message, its only when the field is empty that the above code works and
    doesn't draw the image on the PDF.

    I also tried this:

    If NOT(ISNULL(rsMo tor("Photo").Va lue)) Then
    'Insert Photo
    Params = "x=337; y=408; scalex=.33; scaley=.33"
    Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
    Page.Canvas.Dra wImage SigImage, Params
    End if

    But still got the same error.

    If I don't use any checking code, and have NULL in the image field, I
    get the same error. This must be something to do with the binary
    content, how can I detect if there is binary content?

    Steve
  • Jon Paal [MSMD]

    #2
    Re: A safe array of bytes is expected as an argument






    Comment

    • Dooza

      #3
      Re: A safe array of bytes is expected as an argument

      Jon Paal [MSMD] wrote:Hi Jon,
      Thanks for the pointers, I like the idea of doing it in SQL, as I am
      already using a view to get the data to the page.

      I am still open to other ideas.

      Cheers,

      Steve

      Comment

      • Dooza

        #4
        Re: A safe array of bytes is expected as an argument

        Dooza wrote:
        Jon Paal [MSMD] wrote:>
        Hi Jon,
        Thanks for the pointers, I like the idea of doing it in SQL, as I am
        already using a view to get the data to the page.
        >
        I am still open to other ideas.
        >
        Cheers,
        >
        Steve
        I have gone for a temporary solution, as it seems that as soon as you do
        a length check or isnull check on the binary field it becomes unusable.

        I have used this in my SQL view:

        CASE WHEN (MC.mct_photo IS NULL)
        THEN '0' ELSE '1' END AS PhotoCheck

        And this on my page:

        If rsMotor("PhotoC heck") = 1 Then
        'Insert Photo
        Params = "x=337; y=408; scalex=.33; scaley=.33"
        Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
        Page.Canvas.Dra wImage SigImage, Params
        End if

        Does anyone have any experience with using binary data in asp? Am I
        right in thinking that the starting position has changed due to the
        length check? Is there a way to reset the starting position?

        Cheers,

        Steve

        Comment

        • Dave Anderson

          #5
          Re: A safe array of bytes is expected as an argument

          Dooza wrote:
          I have gone for a temporary solution, as it seems that as soon as you
          do a length check or isnull check on the binary field it becomes
          unusable.
          I have used this in my SQL view:
          >
          CASE WHEN (MC.mct_photo IS NULL)
          THEN '0' ELSE '1' END AS PhotoCheck
          >
          And this on my page:
          >
          If rsMotor("PhotoC heck") = 1 Then
          'Insert Photo
          Params = "x=337; y=408; scalex=.33; scaley=.33"
          Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
          Page.Canvas.Dra wImage SigImage, Params
          End if
          >
          Does anyone have any experience with using binary data in asp? Am I
          right in thinking that the starting position has changed due to the
          length check? Is there a way to reset the starting position?
          Rather than checking for NULL, use DATALENGTH:
          http://msdn2.microsoft.com/en-us/library/ms173486.aspx




          --
          Dave Anderson

          Unsolicited commercial email will be read at a cost of $500 per message. Use
          of this email address implies consent to these terms.


          Comment

          • Dooza

            #6
            Re: A safe array of bytes is expected as an argument

            Dave Anderson wrote:
            Dooza wrote:
            >I have gone for a temporary solution, as it seems that as soon as you
            >do a length check or isnull check on the binary field it becomes
            >unusable.
            >I have used this in my SQL view:
            >>
            >CASE WHEN (MC.mct_photo IS NULL)
            > THEN '0' ELSE '1' END AS PhotoCheck
            >>
            >And this on my page:
            >>
            >If rsMotor("PhotoC heck") = 1 Then
            >'Insert Photo
            >Params = "x=337; y=408; scalex=.33; scaley=.33"
            >Set SigImage = Doc.OpenImageBi nary(rsMotor("P hoto").Value)
            >Page.Canvas.Dr awImage SigImage, Params
            >End if
            >>
            >Does anyone have any experience with using binary data in asp? Am I
            >right in thinking that the starting position has changed due to the
            >length check? Is there a way to reset the starting position?
            >
            Rather than checking for NULL, use DATALENGTH:
            http://msdn2.microsoft.com/en-us/library/ms173486.aspx
            Hi Dave, thats a new one on me, is it SQL only, or can I use it in
            ASP/VBScript?

            Steve

            Comment

            • Dave Anderson

              #7
              Re: A safe array of bytes is expected as an argument

              Dooza wrote:
              >>CASE WHEN (MC.mct_photo IS NULL)
              >> THEN '0' ELSE '1' END AS PhotoCheck
              >>
              >Rather than checking for NULL, use DATALENGTH:
              >http://msdn2.microsoft.com/en-us/library/ms173486.aspx
              >
              Hi Dave, thats a new one on me, is it SQL only, or can I use
              it in ASP/VBScript?
              It's only VBScript if you can find it here:
              http://msdn2.microsoft.com/en-us/library/d1wf56tt.aspx

              The link I provided is Transact-SQL. I meant for you to understand that you
              can use it in this manner:

              SELECT
              MC.mct_photo,
              DATALENGTH(MC.m ct_photo) AS Bytes,
              ...
              FROM [Your Table]

              This does not require a conditional evaluation in the database. You will be
              using one, regardless, in your web script, so why add another?



              --
              Dave Anderson

              Unsolicited commercial email will be read at a cost of $500 per message. Use
              of this email address implies consent to these terms.


              Comment

              • Dooza

                #8
                Re: A safe array of bytes is expected as an argument

                Dave Anderson wrote:
                The link I provided is Transact-SQL. I meant for you to understand
                that you
                can use it in this manner:
                >
                SELECT
                MC.mct_photo,
                DATALENGTH(MC.m ct_photo) AS Bytes,
                ...
                FROM [Your Table]
                >
                This does not require a conditional evaluation in the database. You
                will be
                using one, regardless, in your web script, so why add another?
                That makes perfect sense and works perfectly too. It will also allow me
                to keep an eye on the size of images in the table.

                Thanks again!

                Steve

                Comment

                Working...