473,772 Members | 2,391 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

String or binary data would be truncated

Coldfire
289 Contributor
i am having error ....details are

ASP.Net application...i n which I have a textbox
<asp:TextBox ID="Other" TextMode=Single Line CssClass="servi ceBox" Width="250" Height="45" Runat="server" MaxLength="1000 " /></asp:TextBox>

and this textbox is in a <asp:Repeater > which has the count of 35.

The textbox value is stored in the SQL DB
And the field data-type in the SQL DB is VARCHAR(1000)

Now the problem comes when I enter the text in the textbox with length more than 100(hundred) characters . The error that shows up is

----------------------
String or binary data would be truncated. The statement has been terminated.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.Sql Client.SqlExcep tion: String or binary data would be truncated. The statement has been terminated.

Stack Trace:

[SqlException: String or binary data would be truncated.
The statement has been terminated.]
System.Data.Sql Client.SqlComma nd.ExecuteReade r(CommandBehavi or cmdBehavior, RunBehavior runBehavior, Boolean returnStream) +723
System.Data.Sql Client.SqlComma nd.ExecuteNonQu ery() +195
XXXXXX.SqlHelpe r.ExecuteNonQue ry(SqlConnectio n connection, CommandType commandType, String commandText, SqlParameter[] commandParamete rs)
XXXXXX.SqlHelpe r.ExecuteNonQue ry(String connectionStrin g, CommandType commandType, String commandText, SqlParameter[] commandParamete rs)
XXXXXXL.SqlHelp er.ExecuteNonQu ery(String connectionStrin g, String spName, Object[] parameterValues )
XXXXXX.Utilitie s.InsertCustome rService(Int32 MemberID, String OfferID, String CantAccess, String WontFunction, String Other)
----------------------

Now what i couldnt get is....the field length gives error when i give text more than 100 characters..... ..whats the deal with it..plz help asap!
Mar 5 '07 #1
7 17712
Coldfire
289 Contributor
in connection to my above query .......these are some more of the insights
regarding the error...i have found out that the main issue is in storedprocedure . But here in the SP , the length of the field is ntext rather than varchar(1000). But still it is not inserting values greater than 100 length

Msg 8152, Level 16, State 2, Procedure up_InsertCustom erService, Line 12
String or binary data would be truncated.
The statement has been terminated.
Mar 5 '07 #2
kenobewan
4,871 Recognized Expert Specialist
Have you made changes to the design or stored procedure recently? Please post the stored procedure. Thanks.
Mar 6 '07 #3
Coldfire
289 Contributor
Have you made changes to the design or stored procedure recently? Please post the stored procedure. Thanks.
"up_InsertCusto merService" this is the stored procedure it has been using

[HTML]set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
go


ALTER PROCEDURE [dbo].[up_InsertCustom erService]

@MemberID int,
@OfferID varchar(100),
@CantAccess varchar(100),
@WontFunction varchar(100),
@Other ntext

AS

INSERT INTO
CustomerService
(
MemberID,
OfferID,
CantAccess,
WontFunction,
Other
)
SELECT
@MemberID,
OfferIDList.Val ue,
CantAccessList. Value,
WontFunctionLis t.Value,
OtherList.Value
FROM
ufn_ConvertList ToTable(@OfferI D) OfferIDList
JOIN ufn_ConvertList ToTable(@CantAc cess) CantAccessList ON CantAccessList. ID = OfferIDList.ID
JOIN ufn_ConvertList ToTable(@WontFu nction) WontFunctionLis t ON WontFunctionLis t.ID = OfferIDList.ID
JOIN ufn_ConvertList ToTable(@Other) OtherList ON OtherList.ID = OfferIDList.ID


[/HTML]
and the function "ufn_ConvertLis tToTable" is
[HTML]set ANSI_NULLS ON
set QUOTED_IDENTIFI ER ON
go


ALTER FUNCTION [dbo].[ufn_ConvertList ToTable] (@list ntext)
--set the Value varchar(100) to ntext
RETURNS @tbl TABLE (ID INT IDENTITY, Value ntext NOT NULL) AS
BEGIN
DECLARE
@pos int,
@textpos int,
@chunklen smallint,
@str nvarchar(4000),
@tmpstr nvarchar(4000),
@leftover nvarchar(4000)

SET @textpos = 1
SET @leftover = ''
WHILE @textpos <= datalength(@lis t) / 2
BEGIN
SET @chunklen = 4000 - datalength(@lef tover) / 2
SET @tmpstr = ltrim(@leftover + substring(@list , @textpos, @chunklen))
SET @textpos = @textpos + @chunklen

SET @pos = charindex('|', @tmpstr)
WHILE @pos > 0
BEGIN
SET @str = substring(@tmps tr, 1, @pos - 1)
INSERT @tbl (Value) VALUES(@str)
SET @tmpstr = ltrim(substring (@tmpstr, @pos + 1, len(@tmpstr)))
SET @pos = charindex('|', @tmpstr)
END

SET @leftover = @tmpstr
END

IF ltrim(rtrim(@le ftover)) <> ''
INSERT @tbl (Value) VALUES(@leftove r)

RETURN
END




[/HTML]

I have found out the same reason of datatype mismatch or data-overflow but not yet pinpointed that at where in function "ConvertListToT able" it needs to be changed
Mar 6 '07 #4
Coldfire
289 Contributor
hurray ........... i have changed "@list ntext" to "@list varchar(1000)" and Value "varchar(10 0)" to "varchar(10 00)" in the below given function that was called from my SP......Now its working fine ;)

[HTML]
ALTER FUNCTION [dbo].[ufn_ConvertList ToTable] (@list ntext)
--set the Value varchar(100) to ntext
RETURNS @tbl TABLE (ID INT IDENTITY, Value ntext NOT NULL) AS
BEGIN
DECLARE
[/HTML]


regards
Saad
_______________ _______________ ______________
Mar 6 '07 #5
kenobewan
4,871 Recognized Expert Specialist
Well done, thanks for sharing the solution :).
Mar 7 '07 #6
vainternet
1 New Member
or u could use ntext, it is bigger than varchar(1000)

here is a function for cutting the length of user data


Expand|Select|Wrap|Line Numbers
  1. public static string CutString(string text, int chars)
  2.     {
  3.         StringBuilder MyStringBuilder = new StringBuilder(text, chars);
  4.         if (MyStringBuilder.Length > chars)
  5.         {
  6.             MyStringBuilder.Length = chars;
  7.         }
  8.         return Common.deConverttoHtml(MyStringBuilder.ToString());
  9.     }
Jan 22 '08 #7
Baghul Mughal
1 New Member
Typically this error happens when there is a mismatch between data types. I have seen this error occur in many places including SSIS, Reporting Services and procs.

I would say use either CAST or CONVERT functions to make sure you are getting the correct data type and data length when passing the values.


Baghul
Instructor
Mar 24 '11 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

1
39782
by: TZone | last post by:
Is there anything I can put in a stored procedure so instead of proc falling over because of "String or binary data would be truncated" the offending records are just truncated? Thanks for any help!
3
40182
by: RDRaider | last post by:
How can I find which record(s) cause this error: Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. I have tried Profiler but I can't get it to tell me which records are causing the error. Here's the script I'm running: EXEC sp_executesql N'UPDATE IMDISFIL_SQL
0
1264
by: benh | last post by:
Does anyone have any insight into how Application Center Test handles binary data in a response body? My problem: I need some specific data from inside a PDF file that is coming down as the response body. The response contains binary data mixed with plain text which is where my data lies. Unfortunately, when I print the response body to the Trace Log it is truncated. The response ContentLength is about 21,000 bytes so I have used...
1
2813
by: Bernie Yaeger | last post by:
What causes the error 'string or binary data would be truncated'? Here's the routine that sometimes causes the error, sometimes not: irow("ctotal") = FormatCurrency(irow("total"), 2, TriState.False, TriState.True, TriState.True) ctotal is a char column in an sql server table; total is a currency column in the same table. Notwithstanding, the conversion appears to be made, even though the exception is being thrown. Any help would be...
1
8076
by: languy | last post by:
Hi there I'm having a problem when using the SqlDataAdapter. When calling the Update(DataSet, string) method I get the following error message "String or binary data would be truncated". The rows neither have data that exceeds 8000 chars nor contain any LOB fields. Furthermore the data is transferred between two tables that are bitwise identical. -- snip -- System.Data.SqlClient.SqlCommand command =
0
1766
by: dileepkumar | last post by:
I'm trying to save file data to sqlserver. file data is converted to sysyte.io.stream and passed through webservice and in Business layer i changed the stream to byte array and passed it as a parameter to my stored procedure. Image file or storing in database. but when i try to save a text file its giving an exception "string or binary data would be truncated \r\n the statement has terminated". I used sqlDBType.Image for the parameter tyep....
6
13332
by: dtarczynski | last post by:
Hello. I have problem when i inserting strings with special characters into MS SQL 2005 database for example: http://www.netsprint.pl/serwis/search?q=http%3A%2F%2Fwww%2Ejobpilot%2Epl%2Fprofile%2Frss20%2F%3Ftitle%3Djobpilot%2Epl%2B%2D%2Boferty%2Bpracy%26region%5B%5D%3D505%26appkind%5B%5D%3D1%2C2%26language%5B%5D%3D11%26profession%5B%5D%3D12%2C65%2C14%2C59%26industry%5B%5D%3D19%2C48%2C23%2C24%2C16%2C33%2C26%26limit%3D10 Then i getting this...
1
2393
by: dreamer247 | last post by:
hii My insert quary is giving an error "Server: Msg 8152, Level 16, State 9, Line 1 String or binary data would be truncated. The statement has been terminated. " What may be the reason of that error.
2
19324
by: sunkesula | last post by:
I update a field in the database that gives the last update time. The first time I edit the item it puts a value in this field. The second time the applications fails with The statement has been terminated. String or binary data would be truncated. What's the deal?? There is enough space for the date/time so I am not sure what is going on here.. Anyone have any ideas?
0
9454
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10261
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10103
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10038
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8934
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7460
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6713
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5354
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
3
2850
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.