By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,997 Members | 1,098 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,997 IT Pros & Developers. It's quick & easy.

[C#, MS SQL Server] String or binary data would be truncated. But not field length problem.

P: n/a
Hello.
I have problem when i inserting strings with special characters into MS
SQL 2005 database for example:
http://www.netsprint.pl/serwis/searc...6%26limit%3D10

Then i getting this error:
String or binary data would be truncated.
The statement has been terminated.

It's not a problem with database field length (not working with text,
varchar(1024) etc)

Any ideas?. Thanks in advance.

Regards
Darek

Jan 25 '07 #1
Share this Question
Share on Google+
6 Replies


P: n/a
Well, I don't know about the message, but encoding / collation could be
an issue... have you tried ntext, nvarchar, etc?

Marc

Jan 26 '07 #2

P: n/a


On 26 Sty, 06:15, "Marc Gravell" <marc.grav...@gmail.comwrote:
Well, I don't know about the message, but encoding / collation could be
an issue... have you tried ntext, nvarchar, etc?

Marc
Yes, I'd tried ntext, nvarchar, text etc. This doesn't solve my
problem. Any ideas what colation should i chose?

Jan 26 '07 #3

P: n/a
In that case I suspect that you are somewhere using default lengths...

specifically, are you specifying the length property of the parameter
when adding it to the collection? In your SQL are you declaring the
parameter with size? Are you doing anything that might mess this up?
Any temp variables? concatenations? trims? Triggers that might be
expecting shorter strings.

I suspect the devil is in the detail here...

Marc
Jan 26 '07 #4

P: n/a


On 26 Sty, 10:08, "Marc Gravell" <marc.grav...@gmail.comwrote:
In that case I suspect that you are somewhere using default lengths...

specifically, are you specifying the length property of the parameter
when adding it to the collection? In your SQL are you declaring the
parameter with size? Are you doing anything that might mess this up?
Any temp variables? concatenations? trims? Triggers that might be
expecting shorter strings.

I suspect the devil is in the detail here...

Marc
Im exectuting commands as strings for example:
string varStrLongPhrase = "somelongAndProblematicsValues";
cmd.CommandText = String.Format("INSERT INTO table1 VALUES ('{0}');
",varStrLongPhrase);
cmd.ExecuteNonQuery();

And this isnt'working as MS SQL sql scritpt to (when I trying exectue
this in MS Sql server manager.

Jan 26 '07 #5

P: n/a
And this isnt'working as MS SQL sql scritpt to (when I trying exectue
this in MS Sql server manager.
Ofcourse in sql manager im trying exectute tsql statemment (Insert into
.....) - not this code above :-)

Jan 26 '07 #6

P: n/a
Well, without reproducable code it is hard to say for sure... however,
one first thing to try is parameterised queries, i.e. using the
parameters collection. A stored procedure is optional - you can use
parameters without them. This will also also prevent injection
attacks, but can be especially useful with long strings (esp. text) as
parameters. It would certainly be the next thing I would try...

Marc

Jan 27 '07 #7

This discussion thread is closed

Replies have been disabled for this discussion.