SQL Error - String or binary data would be truncated

by Naveen 9. August 2010 10:57

Some times when you execute a SQL query to insert or update data into a table, you may see the following error.


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.SqlClient.SqlException: String or binary data would be truncated.
The statement has been terminated.

What this error means is that you are trying to insert more data into a field than the schema specified for. For example if you have a varchar field and limited its size to 100, if you try to insert a string with length more than 100, then you will end up with this exception. In older version of SQL, the server used to silently let this case go through and truncate the data and you would not know it. And then you will notice it when trying to display these fields in some form.

Give your advice to big bosses and make money

Views: 451

Tags: , ,

ADO.Net | SQL Server | TSQL

ADO.Net Dataservice Error: Request Error Server Encountered an error processing request

by Viper 5. January 2009 09:03

I was working on a silverlight application that was connecting to an ADO.Net dataservice on my server. All of a sudden I started getting following error.

Request Error: The server encountered an error processing the request. See server logs for more details

I looked at event logs and sql server logs. I could not find anything wrong in the logs. Then I started thinking back to figure out what did I change in service that may have caused anything to break. Only thing I remember changing was that sql connection was changed from windows authentication to sql authentication. I looked at connection string and everything looked fine there as well. I tested the credentials and they were fine. After banging my head for few minutes I tried couple of URL in service and nothing worked. I fired up SQL profiler and started monitoring the requests. I did not see a single query making into it from ADO.Net data service. I looked at connection string again and there you go. There was typo. Instead of "User ID" I had typed "UserID" to provide login name. After I fixed that, everything worked like a charm.

You can see that error message from data service was not very helpful. So every time you run into this obscure error, make sure that you check names in query strings etc. to make sure there are no typos.

Give your advice to big bosses and make money

Views: 4013

Tags: ,

ASP.Net | Silverlight | ADO.Net | DataService

Powered by BlogEngine.NET 1.5.1.7
Theme by Naveen Kohli

By Categories