Solved

What is this error telling me I am doing wrong.

Posted on 2012-04-12
9
254 Views
Last Modified: 2012-04-29
I am using this code in a script that uploads files to an SQL 2008 server. It produces an error that I can not figure out. What is this error telling me I am doing wrong. As far as I know I am passing these values in my script.

ERROR
The parameterized query '(@fileData varbinary(max) ,
@fileGuid uniqueidentifier,
@fileName ' expects the parameter '@fileData',
 which was not supplied.

SCRIPT
    Const SQL_INSERT As String = "INSERT INTO [imageFile] ([fileGuid],[fileName],[fileData],[fileId])" & _
                                                  "values (@fileGuid, @fileName, @fileData); select @fileId = SCOPE_IDENTITY()"

               cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, -1)

                cmdInsert.Parameters.Add("@fileGuid", SqlDbType.UniqueIdentifier)
                cmdInsert.Parameters("@fileGuid").Value = file.fileGuid

                cmdInsert.Parameters.Add("@fileName", SqlDbType.VarChar, 256)
                cmdInsert.Parameters("@fileName").Value = file.newFileName

                cmdInsert.Parameters.Add("@fileId", SqlDbType.BigInt)
                cmdInsert.Parameters("@fileId").Direction = ParameterDirection.Output
0
Comment
Question by:ruffone
9 Comments
 
LVL 33

Expert Comment

by:knightEknight
ID: 37839620
at first glance it looks like you are specifying 4 columns in the insert list, but only 3 values:

INSERT INTO [imageFile] ([fileGuid], [fileName], [fileData], [fileId])" & _
                            "values (@fileGuid, @fileName, @fileData)
0
 
LVL 20

Expert Comment

by:BuggyCoder
ID: 37839661
assign a value to @filedata parameter like this:-

  cmdInsert.Parameters("@fileData").Value = <SomeFileBinaryData>
0
 
LVL 4

Author Comment

by:ruffone
ID: 37840187
If I must use a value I only want to pass a single byte(). How do I assign a single byte()
0
 
LVL 10

Expert Comment

by:adriankohws
ID: 37843663
So long your codes behind changed the data into binary, it doesn't matter so long it doesn't exceed the maximum size allowed.
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 83

Expert Comment

by:CodeCruiser
ID: 37853667
Try changing

 cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, -1)

to

 cmdInsert.Parameters.Add("@fileData", SqlDbType.VarBinary, System.Text.Encoding.ASCII.GetBytes(" "))
0
 
LVL 4

Author Comment

by:ruffone
ID: 37857159
This is a project that I am moving from my VS10 development environment into VS11 Beta DE. while tweaking my classes. I did not figure out what caused the error but when I reimported my bits from VS10 into VS11 and made my changes incrementally I did not end up with the error. Thank you all for your responses
0
 
LVL 4

Author Comment

by:ruffone
ID: 37866926
I figured out that the upload process fails when I check "IsImage". When I comment that line then the the process completes successfully I have no ides why this happens


    If filePath.InputStream.Length > -1 Then
        _fileData = filePath.InputStream
        If IsImage(_fileData) = False Then
            Exit Sub
        End If
        ...
    End If

    Private Function IsImage(file As Stream) As Boolean
        Using bitmap As New Bitmap(file, False)
            If bitmap.RawFormat.Equals(ImageFormat.Bmp) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Jpeg) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Gif) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Png) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Tiff) Then
                Return True
                Exit Function
            End If
            If bitmap.RawFormat.Equals(ImageFormat.Icon) Then
                Return True
                Exit Function
            End If

            Return False
        End Using
    End Function
0
 
LVL 4

Accepted Solution

by:
ruffone earned 0 total points
ID: 37889326
0
 
LVL 4

Author Closing Comment

by:ruffone
ID: 37907553
Thanks guys
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

I wrote this interesting script that really help me find jobs or procedures when working in a huge environment. I could I have written it as a Procedure but then I would have to have it on each machine or have a link to a server-related search that …
Introduction SQL Server Integration Services can read XML files, that’s known by every BI developer.  (If you didn’t, don’t worry, I’m aiming this article at newcomers as well.) But how far can you go?  When does the XML Source component become …
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

8 Experts available now in Live!

Get 1:1 Help Now