Wednesday, March 7, 2012

Error message: String or binary data truncated

Hi, all!
I encountered that error message while testing my application using
MSDE. It appears when I issue this type of statement:
INSERT INT atable (Col1, Col2, ...)
VALUES (Val1, Val2,...)
The string columns are of type 'char'.
The strange is that the message does not appear always. In one case I
had error in two consecutive executions of the query. After that, in the
3rd execution *with exactly the same data!* all went OK!? I cannot
understand where lies the problem.
The same thing does not happen at all when testing with MS SQL Server 2000.
Please, can somebody give me a hint about what probably goes on.
hi Lazar,
Lazar Videnov wrote:
> Hi, all!
> I encountered that error message while testing my application using
> MSDE. It appears when I issue this type of statement:
> INSERT INT atable (Col1, Col2, ...)
> VALUES (Val1, Val2,...)
> The string columns are of type 'char'.
> The strange is that the message does not appear always. In one case I
> had error in two consecutive executions of the query. After that, in
> the 3rd execution *with exactly the same data!* all went OK!? I cannot
> understand where lies the problem.
> The same thing does not happen at all when testing with MS SQL Server
> 2000.
> Please, can somebody give me a hint about what probably goes on.
are you sure this is not depending on the provided values exceeding the
maximum storage of the columns?
DECLARE @.t TABLE (
c char(5)
)
INSERT INTO @.t VALUES ( 'abcdefghi' )
--<--
Server: Msg 8152, Level 16, State 9, Line 4
String or binary data would be truncated.
The statement has been terminated.
Andrea Montanari (Microsoft MVP - SQL Server)
http://www.asql.biz/DbaMgr.shtmhttp://italy.mvps.org
DbaMgr2k ver 0.12.0 - DbaMgr ver 0.58.0
(my vb6+sql-dmo little try to provide MS MSDE 1.0 and MSDE 2000 a visual
interface)
-- remove DMO to reply
|||Hi,
Actually, I don't do any checks for exceeding the storage space in the
string columns. I thought about that, but the strange is that this error
happens only sometimes. That is why I'm curious. And, as I wrote, it
works all fine in MS SQL Server 2000. I thought that the server just
trims the data and everything is OK.
Now, I'll make sure that I pass strings with length less than the
definition of the column, and I'll test again.
thanks

No comments:

Post a Comment