Entity Framework - line size exceeding the permissible maximum line size of 8060

I have an object with a binary data type and the corresponding varbinary(max) column in SQL Server. EF creates this:

 CREATE TABLE [dbo].[Attachments] ( [Id] INT IDENTITY(1,1) NOT NULL, [FileName] NVARCHAR(255) NOT NULL, [Attachment] VARBINARY(MAX) NOT NULL ); 

When I try to call .SaveChanges() from the Entity Framework, I get an error:

Cannot create a string of size 8061 that is larger than the allowable maximum string size of 8060

I understand the error, there are a lot of things on Google, but I don’t understand why I get it. Shouldn't this be managed by Entity Framework / SQL Server?

Richard

+6
source share
1 answer

The only way I see you getting this error with this table definition is if you previously had a large fixed-width column that has since been deleted.

 CREATE TABLE [dbo].[Attachments] ( [Id] int IDENTITY(1,1) NOT NULL, [FileName] nvarchar(255) NOT NULL, [Attachment] varbinary(max) NOT NULL, Filler char(8000), Filler2 char(49) ); ALTER TABLE [dbo].[Attachments] DROP COLUMN Filler,Filler2 INSERT INTO [dbo].[Attachments] ([FileName],[Attachment]) VALUES ('Foo',0x010203) 

What gives

Msg 511, Level 16, State 1, Line 12 It is not possible to create a line of size 8075 which is larger than the allowable maximum size of line 8060.

If so, try rebuilding the table.

 ALTER TABLE [dbo].[Attachments] REBUILD 
+17
source

Source: https://habr.com/ru/post/898497/


All Articles