[.net] Help with a common Sql Server Error

Started by
5 comments, last by MButchers 18 years, 1 month ago
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
Advertisement
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.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
okay, thanks... how do I fix it... step by step. Remember, I'm stupid, and don't know c. want a copy of the source?
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.
"Pfft, Facts! Facts can be used to prove anything!" -- Homer J. Simpson
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.
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).
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

This topic is closed to new replies.

Advertisement