1

We trying to save article (long string) in database column using EF6 database first, the article character is more than 4000 char so we changed the column type from NVARCHAR(4000) to VARCHAR(8000) but after when we tried to save in database, We found the data saved as quationmark '???? ???? ????' , we changed the column collation to Arabic_CI_AI as following :

ALTER TABLE laws.ArticleContent ALTER COLUMN TextAr VARCHAR(8000) COLLATE Arabic_CI_AI

but still have the same problem also we update the Edmx after we changed the column properties but still the same, and we change the property in Edmx to Unicode = true and we got the same, so please any help

We use MSSQL2008R2 and EF6 database first

the table after insert :

enter image description here

the Edmx Update : enter image description here

the table after update column collation : enter image description here

AHMAD
  • 95
  • 11
  • varchar and nvarchar are not the same. nvarchar uses unicode characters. each unicode character is TWO bytes. varchar uses non-unicode characters, which means each character is ONE byte, so you see... you are trying to save a two-bytes character into a one-byte character! – Sparrow Nov 23 '17 at 22:54
  • when i don't use EF for example insert data from SQL management the data insert correctly but when i use EF data send to database like like '???? ??? ????' – AHMAD Nov 23 '17 at 22:58
  • Run the query analyzer while you are saving the data through EF and find the SQL statement that is generated by EF. That should help. I am guessing EF is passing the data as unicode – Sparrow Nov 23 '17 at 23:00

1 Answers1

2

Change the column data type to nvarchar(max)
by default this will set the field length to 4000 unless you send data exceed the 4000, it will will convert it to a pointer to a data.

Some helpful questions and answers:
What is the maximum characters for the NVARCHAR(MAX)?
Are there any disadvantages to always using nvarchar(MAX)?

Amr Elgarhy
  • 66,568
  • 69
  • 184
  • 301
  • it's work for me thank to much, but why MSSQL column not accepted more than 4000 char as NVARCHAR and wen we put MAX take more than 4000 and what do you mean with "it will will convert it to a pointer to a data." tank you again – AHMAD Nov 24 '17 at 10:17
  • 1
    @AHMAD this https://social.msdn.microsoft.com/Forums/sqlserver/en-US/d5e0c6e5-8e44-4ad5-9591-20dc0ac7a870/nvarcharmax?forum=transactsql explain it and this https://learn.microsoft.com/en-us/sql/t-sql/data-types/nchar-and-nvarchar-transact-sql – Amr Elgarhy Nov 25 '17 at 22:01
  • @AHMAD feel free to accept the answer if it solved your issue, thanks – Amr Elgarhy Nov 26 '17 at 21:22