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 :
the Edmx Update :
the table after update column collation :
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)?
Related
In my service-based SQL database one of my table has a column 'feedbackdate' with default value GETDATE(). I am using entity framework to insert data to the table and not mentioning the said column in the insert statement but GETDATE() function is inserting 01/01/001 12:00:00 AM . I also tried current_timestamp and sysdatetime() and sysdatetime().NOW() as Default-Value but result is same.
I also changed the DataType of column from date to datetime2(0) but no luck.
Column definition in table
[feedBackDate] DATETIME2 (0) DEFAULT (sysdatetime()) NOT NULL,
Note: I am using Database-First Model and in EntityDataModel the mapped column's Default Value is NONE
I've got it. The problem is with the Mapped Column in .edmx file. I've changed the StorGenereatePattern from None to Computed of the mapped column and bingo.
create table article
(
ArticleID int constraint cnst-name Primary key,
Description datatype
)
I am creating this table in SQL Server 2014. I am trying to create a table where I can store articles with huge data (it can be 1000-2000 words article description). I don't know which data type to choose for description column.
I chose varchar(max) but there is a limitation that each row has to be <= 900 bytes. Please guide me if my table structure is right.
Thanking in anticipation.
Use VARCHAR(max).
2000 words in a .txt file is around 13kb.
I would not call that 'huge'.
I would use nvarchar(max). Unlike varchar is supports unicode. The limit 2GB should be enough.
The limit of row size is 8060B, so You can not store more than about 4000 unicode characters in the row. But the restriction does not apply here, because nvarchar(max) is not stored in the row. The row contains pointer only. This one indirection is the price for the "unlimited" size.
I am having a problem with writing a string to a mysql database that contains a utf-8 character. Everything before the character gets written to the table, but the character and everything after it is not there.
I have checked the character sets of the database and the default collation is utf8_general_ci and the default characterset is utf8. The column being written to is type longtext with the collation utf8_general_ci.
I have also tried adding SET NAMES utf8; to the query but this did not change the result.
Here is an example of the code being run:
using (var cmd = new MySqlCommand("insert into tablename (BodyText) values (#p1)", connection as MySqlConnection) { CommandType = CommandType.Text })
{
cmd.Parameters.Add("#p1", BodyText);
cmd.ExecuteNonQuery();
}
The connection string is:
"SERVER=xx;DATABASE=xx;USER=xx;PASSWORD=xx;Pooling=true;Validate Connection=true;CHARSET=UTF8"
And the text that is attempting to write to the table is "Thank you! I saw it as a 2 😝 more text...", and what is written to the table is "Thank you! I saw it as a 2 ".
Any help on the matter would be appreciated.
Update: After further research the problem appears to be that the base utf8 encoding in MySql does not support 4-byte characters (of which 😝 is). The solutions to this are either to update the MySql database to use utf8mb4 or remove the characters from the string before writing to the table. The problem with the second solution is on a large codebase this check would have to be done everywhere text is written to the database. Any suggestions on how to handle this issue would be welcome.
You can probably to this to change from utf8 to utf8mb4 in a table without losing or mangling any data:
ALTER TABLE tbl MODIFY COLUMN col ... CHARACTER SET utf8mb4 ...;
(Where the '...' is the stuff currently used to define the column, such as LONGTEXT.) You might want to specify the collation at the same time.
If that fails, this will probably work:
ALTER TABLE Tbl MODIFY COLUMN col LONGBLOB ...;
ALTER TABLE Tbl MODIFY COLUMN col LONGTEXT ... CHARACTER SET utf8mb4 ...;
If col is in any indexes, you might want to DROP INDEX in the first ALTER and ADD INDEX in the second. (This is for efficiency and possibly to avoid index limitations.)
I have a column in table with text datatype and trying to save some string value to this column from C# code. Issue comes when I use some very large string.
I am not able to save more than 43679 character into text field. I know text size can be 2^31.
I also tried saving same value from SSMS and noticed same scenario.
There is nothing special about code, but still SQL query is given below...
update TableName
set ColumnName = 'some text more than 43679 char'
where id=<some int id>
just to mention... column is declare in table as
[columnname] [text] NULL
Can anyone tell me what could be wrong.
You can try to use varchar(max) to store huge amount of data. See MSDN
We recommend that you store large data by using the varchar(max),
nvarchar(max), or varbinary(max) data types. To control in-row and
out-of-row behavior of these data types, use the large value types out
of row option.
You can also check the same issue here: SSMS - Can not paste more than 43679 characters from a column in Grid Mode
How do I call a stored procedure without error in ADO.NET Entity Framework? If I use the code below, I get an error:
adminNameContext.AddItemCategory(12, "ggf", DateTime.Now);
Error:
The data reader is incompatible with the specified 'NetTanitimTestModel.Categories'. A member of the type, 'ID', does not have a corresponding column in the data reader with the same name.
ALTER procedure [dbo].[sp_AddItemCategory]
(
#item int,
#category nvarchar(50),
#date smalldatetime
)
as
begin
if(#item=-1)
begin
insert into Categories(PARENTID,Category,Date) values(null,#category,#date)
end
else
begin
insert into Categories(PARENTID,Category,Date) values(#item,#category,#date)
end
end
i have Categories table which has got 3 columns: PARENTID,Category,Date
It looks as if your EF data model and your database are not in sync anymore. It seems as if your "Categories" object in the EF data model has an "ID" field but the table does not.
I would update the EF data model from the database and see if that fixes the problem. To do this, open up the EDMX designer and right click on an empty spot in the design surface, and pick the "Update model from database" option. That should bring the two worlds back into sync.
Marc
Mitch Wheat gave you the answer. You're trying to use the ID column, but the table has a PARENTID column.