0

I want to save file to my SQL Server; the column type is varbinary(max).

When I try to save, I get an error:

Cannot create a row of size 8091 which is greater than the allowable maximum row size of 8060.

This is the code

Using fs As New IO.FileStream(OpenFileDialog2.FileName, IO.FileMode.Open, IO.FileAccess.Read)
    If fs.Length <= Int32.MaxValue Then
        Dim bytes(CInt(fs.Length - 1)) As Byte
        fs.Read(bytes, 0, CInt(fs.Length))

        Dim docfile As New SqlParameter("@d39", SqlDbType.VarBinary)
        docfile.Value = bytes

        cmd.Parameters.Add(docfile)
    End If
End Using

from OP's comment: Table Schema:

CREATE TABLE [dbo].[empolyee] (
    [Emp_code] [int] NOT NULL
    ,[arabicname] [nchar](250) NOT NULL
    ,[worktime] [nvarchar](250) NULL
    ,[filedata] [varbinary](max) NULL
    ,CONSTRAINT [PK_empolyee] PRIMARY KEY CLUSTERED ([Emp_code] ASC) WITH (
        PAD_INDEX = OFF
        ,STATISTICS_NORECOMPUTE = OFF
        ,IGNORE_DUP_KEY = OFF
        ,ALLOW_ROW_LOCKS = ON
        ,ALLOW_PAGE_LOCKS = ON
        ) ON [PRIMARY]
    ) ON [PRIMARY] GO
Prabhat G
  • 2,974
  • 1
  • 22
  • 31
  • 2
    Please show us the **table structure** of that table you're inserting your data into .... – marc_s Oct 16 '17 at 09:02
  • 2
    Possible duplicate of [Entity Framework - Row size greater than allowable maximum row size of 8060](https://stackoverflow.com/questions/7631546/entity-framework-row-size-greater-than-allowable-maximum-row-size-of-8060) – Dzmitry Paliakou Oct 16 '17 at 09:38
  • Please **do not** put code samples or sample data into comments - since you cannot format it, it's **extremely hard** to read it.... Instead: **update** your question by editing it to provide that additional information! Thank you. – marc_s Oct 16 '17 at 09:59

1 Answers1

0

By the name of the column FileData, I think you trying to store a file in the database.

If this is correct, change the column type to blob.

TINYBLOB    L+1 bytes, where L < 28     256 bytes
BLOB        L+2 bytes, where L < 216    65 kilobytes
MEDIUMBLOB  L+3 bytes, where L < 224    16 megabytes
LONGBLOB    L+4 bytes, where L < 232    4 gigabytes

If you are managing big files you also need to check your sql configuration for the maximum packet size or you will have errors when trying to store large files.

Mr.Alvaro
  • 99
  • 10