Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

LINQ Large string (64k) not inserted into SQL Database

I have a column in SQL varchar(max). Using LINQ, when I'm trying to add a record with a string over 64k large, the value is not saved into DB. I'm simply doing;

test.MyString = LargeString; //(over 64k text)
mydb.myTable.InsertOnSubmit(test);
mydb.SubmitChanges();

Is there a limit when using LINQ to SQL ? What's the correct way to do this?

like image 300
Red Taz Avatar asked Aug 04 '11 15:08

Red Taz


1 Answers

VarChar(Max) supports string of upto 8000 characters (SQL Server 2k). On 2005+ this should not cause error.

You may want to use Text fields; for SQL Server 2005+, VarChar(Max) is preferred.

Important

ntext, text, and image data types will be removed in a future version of MicrosoftSQL Server. Avoid using these data types in new development work, and plan to modify applications that currently use them. Use nvarchar(max), varchar(max), and varbinary(max) instead. Fixed and variable-length data types for storing large non-Unicode and Unicode character and binary data. Unicode data uses the UNICODE UCS-2 character set.

See this for details on VarChar & Text data type

  1. SQL Server Text type vs. varchar data type
  2. MSDN: ntext, text, and image

I noticed you are calling InsertOnSubmit on mydb and calling SubmitChanges on ISNetDB - is this typo or cause of the error.

like image 191
YetAnotherUser Avatar answered Sep 20 '22 04:09

YetAnotherUser