Solved

What is this error telling me I am doing wrong.

Posted on 2012-04-12
9
266 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
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
 
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

SharePoint Admin?

Enable Your Employees To Focus On The Core With Intuitive Onscreen Guidance That is With You At The Moment of Need.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example, show how to extract insert data into a SQL Server database table using the Import/Export option and Bulk Insert.
Viewers will learn how the fundamental information of how to create a table.

687 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