ADO.NET :: Error 'String Or Binary Data Would Be Truncated" When Trying To Upload An Image

Nov 9, 2010

I am getting the error: String or binary data would be truncated. The statement has been terminated. when trying to upload an image. What would cause this? my code is:

protected void Button1_Click(object sender, EventArgs e)
{
if (IsPostBack)
{
HandleUploadedFile();
}
string connectionString = System.Configuration.ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
System.Data.SqlClient.SqlConnection sqlConnection1 =
new System.Data.SqlClient.SqlConnection(connectionString);
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand();
cmd.CommandType = System.Data.CommandType.Text;
cmd.CommandText = "INSERT INTO picstosort (imageurl, useraddy) VALUES (@imageurl, @useraddy)";
cmd.Parameters.AddWithValue("@imageurl", Label5.Text);
cmd.Parameters.AddWithValue("@useraddy", TextBox1.Text);
cmd.Connection = sqlConnection1;
sqlConnection1.Open();
cmd.ExecuteNonQuery();
sqlConnection1.Close();
if (TextBox1.Text != null)
{
string strTo = TextBox1.Text;
string strFrom = "noreply@test.com";
string strSubject = "Picture Uploaded";
SmtpMail.Send(strFrom, strTo, strSubject,
"Thank you for uploading your picture! ");
}
}
private void HandleUploadedFile()
{
string root = Server.MapPath("~/");
if (!root.EndsWith(@""))
root +=@"";
string fileDirectory = root + @"Images";
string link = "<a href='Images/{0}' target='_blank'>{1}</a>{2}{3}";
for (int i = 0; i<Request.Files.Count; i++)
{
HttpPostedFile fi = Request.Files.Get(i);
byte[] fileBytes = new byte [fi.ContentLength];
using (System.IO.Stream stream = fi.InputStream)
{
stream.Read(fileBytes, 0, fi.ContentLength);
}
string fileName = Guid.NewGuid().ToString();
File.WriteAllBytes(fileDirectory + fileName + "_small.jpg",
ResizeImageFile(fileBytes, 10000));
litText.Text += string.Format(link, fileName + "_small.jpg",
fileName + " Small", "<br/>", "<br/>");
Label5.Text = fileDirectory + fileName + ".jpg";
litText.Visible = true;
fileBytes = null;
}}
private static byte[] ResizeImageFile(byte[] imageFile, int targetSize)
{
using (System.Drawing.Image oldImage = System.Drawing.Image.FromStream(new MemoryStream(imageFile)))
{
Size newSize = CalculateDimensions(oldImage.Size, targetSize);
using (Bitmap newImage = new Bitmap(newSize.Width, newSize.Height, PixelFormat.Format24bppRgb))
{
using(Graphics canvas = Graphics.FromImage(newImage))
{
canvas.SmoothingMode = SmoothingMode.AntiAlias;
canvas.InterpolationMode = InterpolationMode.HighQualityBicubic;
canvas.PixelOffsetMode = PixelOffsetMode.HighQuality;
canvas.DrawImage(oldImage,
new Rectangle(new Point(0, 0), newSize));
MemoryStream m = new MemoryStream();
newImage.Save(m, ImageFormat.Jpeg);
return m.GetBuffer();
}}}}
private static Size CalculateDimensions(Size oldSize, int targetSize)
{
Size newSize = new Size();
if (oldSize.Height > oldSize.Width)
{
newSize.Width = (int)(oldSize.Width * ((float)targetSize / (float)oldSize.Height));
newSize.Height = targetSize;
}
else{
newSize.Width = targetSize;
newSize.Height =
(int)(oldSize.Height * ((float)targetSize / (float)oldSize.Width));
}
return newSize;
}
}

View 3 Replies


Similar Messages:

File Upload String Or Binary Data Would Be Truncated

May 17, 2010

I have a website that uploads different file types, creates thumbs from the files and saves the file and thumbs to their respective folders. every so often it throws an exception string or binary data would be truncated, Ive never encountered this locally. I have a problem pinning down the circumstances that it happens, I thought it was documents with spaces in the name but that works sometimes as well. This is really bugging me and I need to fix this. The db table fields are long enough, trust me . Has anyone else ever encountered this issue?

View 1 Replies

SQL Server :: Error: String Or Binary Data Would Be Truncated?

Mar 23, 2011

Whenever I add more than a very short string to the "description" column in my table I get this error. That column (in the DVD table) is set to NVARCHAR(1000). I can't see what the problem is. I've add the procedure that throws exception below.

System.Data.SqlClient.SqlException was unhandled by user code
Message="String or binary data would be truncated.
The statement has been terminated."
Source=".Net SqlClient Data Provider"
ErrorCode=-2146232060

[Code]....

View 3 Replies

Data Controls :: File Upload - String Or Binary Data Would Be Truncated

Jun 20, 2013

I uploaded above 10 mb file i am getting this error..

"String or binary data would be truncated. The statement has been terminated"

my datatype in database is set as varbinary(MAX) then also i am geeting error

View 1 Replies

Web Forms :: Insert Query Error - String Or Binary Data Would Be Truncated

Jul 16, 2012

this is my ImageButton event code

protected void ImageButton_Click1(object sender, ImageClickEventArgs e)
{
string data = Server.UrlDecode(Request.QueryString["BehCode2"])
SqlCommand _cmd = new SqlCommand("insertinfo", _cn);
_cmd.CommandType = CommandType.StoredProcedure;
_cn.Open();

[code]...

View 1 Replies

String Or Binary Data Would Be Truncated - The Statement Has Been Terminated

Nov 11, 2010

String or binary data would be truncated. The statement has been terminated. I'm using the following code but some times(not all the time) i get the above error ....

View 2 Replies

DataSource Controls :: String Or Binary Data Would Be Truncated?

Jan 8, 2010

I tested my app locally and it works perfect, but as soon I publish it, upload it to server and try it, on a 100% copy of my local database it throw me a truncate message; now via this msg

that throws me the error query or via sql profiler I got this query:

[Code]....

View 1 Replies

C# - String Or Binary Data Would Be Truncated. The Statement Has Been Terminated

Apr 9, 2010

I have a SqlCommand object on my c# based asp.net page. The SQL and the passed parameters are working the majority of the time. I have one case that is not working, I get the following error:

String or binary data would be truncated. The statement has been terminated.

I understand the error and but all the columns in the database should be long enough to hold everything being sent.

Is there a way to see what the actual SQL being sent to the database is from SqlCommand object? I would like to be able to email the SQL when an error occurs.

View 4 Replies

DataSource Controls :: Sql Server String Or Binary Data Would Be Truncated?

Feb 11, 2010

I am using Sql server version enterprise edition 9 on win NT.I have an issue with the stored procedure, when I execute the SP I get an error message "String or binary data would be truncated." In general I know that we get this error when the inserted value is greater than the column length, but in this scenario the SP is failing only the for the section 1 insertion. The same SP contains one more section where we are inserting records in to same table from same source table based on some different condition and it works.I wrote a script in which I copied the section from the SP which has the problem and storing the output of it in an temp table and inserting one by one record using cursors in to the destination table and then it works.I tried with the option SET ANSI_WARNINGS OFF and SET ANSI_NULLS ON, but it did not work. I am sure that it is not failing because of the length of the data inserted.Is there are other configuration that i can set??

View 1 Replies

Data Controls :: String Or Binary Data Would Be Truncated - The Statement Has Been Terminated

Mar 26, 2016

CREATE TABLE [dbo].[login] (
[Id] NVARCHAR (50) NOT NULL,
[username] NCHAR (10) NOT NULL,
[password] NCHAR (10) NOT NULL,
[Phone_no] NVARCHAR (50) NOT NULL,
[Email] NVARCHAR (50) NOT NULL,
PRIMARY KEY CLUSTERED ([Id] ASC)

[Code] ....

When I am trying to save the value then get above mentioned error ....

View 1 Replies

Data Controls :: DropDownLists - String Or Binary Data Would Be Truncated

Mar 4, 2013

I have 2 DropDownList and 1 button  in admin.aspx page

1=DDLtradeO and 2=DDLclassO

users should select Item from both of them I use RequiredFieldValidator for both of them and when they click on button in HOuse_info Table it insert their data here when users select first item from DDLtradeO  (that text is="State" )

{ DDLclassO.Enable=false}

below is code

<asp:DropDownList ID="DDLtradeO" runat="server" CssClass="DPCDDLs" AutoPostBack="true" OnSelectedIndexChanged="DDLtrade_SIC">
</asp:DropDownList>

and behind code

protected void DDLtrade_SIC(object sender, EventArgs e) {
if (DDLtrade.SelectedItem.Text != "State") {
BindTrade();
DDLclass.Enabled = true;
Rfv11.Visible = true;
} else {
DDLclass.Enabled = false;
Rfv11.Visible = false;
}

here RFV11 is RequiredFieldValidator for DDlclasso..problem is here when users select other item from DDltradeO and they select Item form DDLcalssO when they click on button it insert data into House_info table correctly but when they select "STATE" Item from DDLtradO (they can't select Item from DDlcalssO) when they click button this error occurrence Server Error in '/behtop website' Application.

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

Line 312:
Line 313:
Line 314: int result = Convert.ToInt32(_cmd.ExecuteScalar()); Line 315: _cn.Close();
Line 316: //LBLERROR.Text = _cmd.Parameters["@Success"].Value.ToString();

I think its depend to RequiredFieldValidator but I want if users select other Item from DDltrade they select Item from DDLcalssO. Server Error in '/behtop website' Application.

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. Source Error: 

Line 312:
Line 313:
Line 314: int result = Convert.ToInt32(_cmd.ExecuteScalar()); Line 315: _cn.Close();
Line 316: //LBLERROR.Text = _cmd.Parameters["@Success"].Value.ToString();

View 1 Replies

Save Image Into DB In Binary Format Without Upload Control?

Jun 17, 2010

I want to Save image into DB in Binary format without upload control i.e

I have avatar which i want to store by default with user creation.

i know all other steps except how to convert that particular image into binary against btn_CreateUser Click event

View 4 Replies

Controls :: ITextSharp - How To Add Binary Image (Byte Array Or Base64 String) To PDF Document Using C#

May 7, 2015

[URL]

i am failing to get the Base64 string and show it as an image in the output pdf file.

I have a signautre canvas that saves the output directly into the sql database.

View 1 Replies

Controls :: Binary Image Displayed Using BASE 64 String Slows Down Page Loading

May 7, 2015

When I am featching binary images from database and displaying in datalist on asp .net image cotrol. The image display getting too much time. When I click on next button also I take too much time for display next image.

View 1 Replies

C# - How To Write Binary Data "as Is" To Registry (ie: I Have Visible Binary Data As String From Regedit Only)

Feb 23, 2011

I have been googling this and have not come along a working solution for an entire day. I don't know anything about binary data types (as I've never knowingly used them) and I'm trying to write a binary value that I see in the registry, to the registry. Now, all I see is the following [shown below]... and if I try to pass that as a string to the RegSetValueEx in the WinAPI and of course it errors out... I do not know what 'numbers' I need to pass into the lpData As Any, argument of RegSetValueEx (i tried a bit array) in order for it to come out as the following [shown below] in the regedit. I really have no idea, and my tests to place random numbers in the bit array just produce corresponding random "figures" as visible in regedit that I do not understand how to 'tie' them together logically.

here is the culprit!

[Code]...

If I had the following in a string or a bit array, what must I populate the bitarray with so that the registry outputs this [above] when written? or, how can I figure out how to do it? I was hoping there'd be a function that reads my string of binary data and transforms it into the real binary format to submit to the RegSetValueEx function in VB6 or other function in VB.Net or C# (this really is a language agnostic question, and the problem exists in all languages; ie: same process).

View 2 Replies

DataSource Controls :: Error Retrieving Image From DB In Binary Format?

Jun 10, 2010

[Code]....

I am using above mentioned code to insert image in binary format and display

Insertion code is working fine but image cannot be retrieved from DB

(Note: there is no syntex error in Code)

View 1 Replies

Forms Data Controls :: Convert The Binary Image Data Into Image Automatically?

Jun 14, 2010

i need a image control, who is able to convert the binary image data into image automatically, i find one which is paid control by telerik, but i need a freeware of it.

View 3 Replies

Web Forms :: How To Upload Word Doc Into Db As A Binary Data

Jan 19, 2010

i have webform in this i have two controls

fileupload control
view buttoncontrol

using fupload control i want to uplod only word .doc files only and upto 5mb file size restrictins

and i want to save into sqlserver db as binary data.

and after uploading and saving into db when i click viewdoc button i want to open again uploaded doc into ms word client.

View 13 Replies

SQL Server :: Allow Viewers To Upload Data Both Binary And Text?

Sep 7, 2010

I have a web page and want to allow viewers to upload data both binary and text (seperate uploads of course) to a database on the server.

View 1 Replies

DataSource Controls :: String Is Truncated When Inserted Into DB?

Feb 10, 2010

I am trying to insert some string values into database.

The problem here is that, the string is truncated without warning..

Here is my vb.net code

[Code]....

And here is how I declared the varible in stored procedure

[Code]....

And If I insert "myCode01234567890" then it's truncated without warning at all.

How can I let it throw an exception rather then truncate the string without any warnings ?

View 9 Replies

Javascript - Display A Truncated String Using Eval

Jul 29, 2010

I have a ASP gridview control. I have a ASP label control in the item template column. I bind data to the grid using -

<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>

But, the value of this string can be upto 80 characters. But, I cannot afford to have the column length to be so high. And, there are limitations so I cannot use Wrap="true" and limit the column width. So, I figured the solution could be to display only about 50 characters in the grid and display the entire string as a tool tip. I managed to do this by using this -

<ItemTemplate>
<asp:Label ID="lblDesc" runat="server" Text='<%# Eval("Description").ToString().Substring(0,50) %>' ToolTip='<%# Eval("Description") %>'></asp:Label>
</ItemTemplate>

This displays the first 50 characters of the string in the grid column. And, the complete string is displayed as a tool tip when the mouse pointer hovers over the text. But, the problem arises when the string length is less than 50 characters. In this case, an exception is thrown. I tried modifying this piece of code to allow conditional display by checking for the string length. But, I could not get this to work. Is there a way to fix this problem? Can we call a javascript function within Eval() ?

View 2 Replies

How To Download Image (binary Data)

Mar 16, 2011

So, I would like to enable user to perform some download function for image.

I'm storing the image to the database as binary data by the way.

how to download that image?

View 3 Replies

Web Forms :: How To Convert Binary Data To Image

Mar 4, 2010

I have stored images in sql in the form of binary data. Now I want to convert it into image for displaying purpose.

I am doing like this

BLLogin blg = new BLLogin();

View 3 Replies

Access :: Save Image As Binary Data Or Path?

May 5, 2010

i have a requirement where i need to save image to database. Iam in confusion whether to save the path of image in database by saving the image in folder or to save the binary data of image to database.

View 5 Replies

Databases :: How To Create Physical Image From Binary Data In Sybase

Nov 18, 2010

I want to extract an image from a third party Sybase table which has binary data in it.

To store images they use the following query:

SELECT xp_write_file('C:photo-1.gz', col_name) FROM tbl_name

What I am trying to do is convert the binary data stored to a actual physical file using .Net

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved