Solved

What is this error telling me I am doing wrong.

Posted on 2012-04-12
9
265 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
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 
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

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

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

The Delta outage: 650 cancelled flights, more than 1200 delayed flights, thousands of frustrated customers, tens of millions of dollars in damages – plus untold reputational damage to one of the world’s most trusted airlines. All due to a catastroph…
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Via a live example, show how to shrink a transaction log file down to a reasonable size.

738 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