Sign in to follow this  

[.net] Help with a common Sql Server Error

This topic is 4301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

allright, I am in huge trouble here, when I try to save my data Sql Server-style, I get an error like the following: An unhandled exception of type 'System.Data.SqlClient.SqlException' occoured in System.Data.Dll Additional information: String or Binary Data would be truncated. The Statement has been Terminated. What does this mean? I did NOT Program this. I am simply doing some debugging for a friend of whom I cannot get a hold of. Please help an ignorant Programmer! Crazytaco1

Share this post


Link to post
Share on other sites
I ran into this error a lot when I was programming database functionality into our product at work. It means that you are trying to store string or binary data into a column that is too small so it is giving you an error that the data would be truncated if this occurs. For example, you are trying to store a 20 character string into a table column that can only hold 10 characters.

Share this post


Link to post
Share on other sites
Well there are two ways of fixing it, either change the table schema so that the column in question can hold more data or use smaller strings.

I dont know how to do it in .Net because I was using C++ and ODBC but there should be a function to query the column size, then send it a string that is smaller than that size.

Share this post


Link to post
Share on other sites
Okay, thanks I'll run that by my partner tomorrow. Hopefully he can fix it. I'm having an unusually difficult time following his code. i think some stuff saved and some stuff didn't... (Like the size of the database)

Thank you very much for your help.

Share this post


Link to post
Share on other sites
I got this error message when using the NHiberate database library w/ SQL Server 2000. I fixed it by changing the NHibernate datatype from "String" to "StringClob" for that particular property.

You may need to bump up the text length of the column in the database if it's a "varchar" or "nvarchar" column (max of 255 characters there). If you need more space, change it to a "text" column (no character limit).

Share this post


Link to post
Share on other sites
Quote:

You may need to bump up the text length of the column in the database if it's a "varchar" or "nvarchar" column (max of 255 characters there). If you need more space, change it to a "text" column (no character limit).


The maximum size of these field types is

nvarchar = 4000
varchar = 8000

in MS SQL Server 2000

Share this post


Link to post
Share on other sites

This topic is 4301 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this